EMI resets atmega on switching ON relay with inductive load like a 230v fan
This can also be a power shortage as there will be a drop when the relays turn on, depending on you psu it might not respond quick enough, so you get a brown out. I added a bit 4700uF cap on the psu power line to the arduino.