Hardware disconnects when switching relays

What type of load are you switching?
If it’s something that generates electrical noise - a motor, fan, bell, buzzer etc. - then it’s probably EMF that’s flowing back into your Arduino.
In this case the solution is usually a suitably rated capacitor across the relay terminals.