How can I safely power both an Arduino as well as an electromagnetic lock with the same power supply?
As mentioned in other answers, swapping the 7805 linear regulator for a buck regulator would help with heat.

That said, I would believe there is no need for that: your use case should not consume so much power that even a linear regulator would get hot. The components you're powering off the regulator in the diagram would use less than 100mA in total, giving (12V - 5V) * 0.1 A = 0.7 W as maximum amount of heat the regulator would need to dissipate. Likely, when the relay is not energized, you would be using tenth of that at most.

So: check current usage of the different components with a multimeter to see where all that current is going.


The Arduino should consume in order of 15 mA, and there are many ways to reduce that even further: https://learn.sparkfun.com/tutorials/reducing-arduino-power-consumption
The relay board lists 65 mA as working current, and this should be much lower when the relay is not energized
Whatever you're using as the inputs to decide when to trigger the relay... Well, only you know what these are


There are many reasons why the Arduino might become unresponsive after triggering the relay, and it's not possible to tell certainly based on info you've given. Some possibilities:


The code you're running on it has no way of going from triggered state back to untriggered state. You need have a code path that turns off the relay and goes back to waiting for someone press the right buttons or whatever.
The electromagnetic lock consumes too much current when triggered (briefly or constantly), leading to Arduino input voltage dropping. If brief, this can be fixed with capacitor on regulator output (there should be one in any case)
Inductive voltage spike from the lock when it's turned off. A freewheeling diode helps here, i.e. a diode placed in parallel with the lock, the "wrong way" around, such that it should not conduct current. A voltage spike would be reverse to the normal working voltage, and would pass harmlessly through the diode.