5v relay causing short circuit when turned off
Your problem is lack of awareness to EMI solutions

( hundreds on this site alone)


  The problem is not that Relay shorts MCU , rather that a reset condition from ground shift or voltage noise on lines i.e. EMC issue.


Noise glitches may be conducted or radiated by E field (Voltage) or H field (current) when there are high impedance lines close to untwisted inductive back EMF surge voltages.

Since you have tried conductive isolation, that leaves radiated noise isolation.

The solution to this depends on your schematic and layout.

Check for : 


inductive load diode clamp for DC  , RC snubber for inductive AC loads
use ground from power source not shared power ground cable for pulsed loads
twisted pair for inductive loads and coil driver
shielded cable helps as well to suppress the emission over twisted pair or STP - cable proximity and non-parallel orientation
add ferrite sleeves to suppress CM noise.


Opinion (based on experience)


Opto-isolation was unnecessary.
solenoid wiring needs to be twisted pair
solenoid needs a snubber to reduce bandwidth of voltage spike and thus crosstalk voltage to signal/return lines.
DC signal cables ( if any) need to be twisted pair.





plastic film X-rated snubber cap avail from avail from Digikey etc.