PIC microcontroller restarts command
This may be an electromagnetic compatibility (EMC) problem.
I used to perform a test that always works: put a relay close to a microcontroller and deenergize it and you will see how the microcontroller will either stall (starts executing an unexpected code in the memory) or restart. This test was a good way to test the Watchdog timer reset.
try to put a LED with a resistor in place of each relay. If the problem is solved then it is an EMC problem and in this case separate physically the relays or use enhanced drivers to avoid this problem. If the problem persists reconsider reviewing your program.
The EMC could also come from the power supply. Separate the Power supplying the relays from the power supplying the microcontroller. Use filters (capacitors) in the right places.
The problem can also be a weak power supply that drops when current is high. or dynamically inefficient in regulation.