I would suggest that when the relay closes/opens and makes/breaks the 400 VDC, it may be generating an EM wave that crashes or stops dead your MCU.
I would look into this possibility.
You can try adding snubbers across your relay contacts. These are traditionally an RC network that absorbs the energy that would otherwise arc across the contacts. There may be other, more modern contact suppressors you can try.
It may not be the same reason but for the record...
I had a major problem with a design many years back, where a mechanical relay was switching the mains going to an AC motor. When the relay opened, our microprocessor (MPU) froze completely. There was no bus activity and only cycling the power let the MPU recover. This was a repeatable fault and occurred on six test machines. It took me two days of hunting to find the cause. It was when I tried it with the lights off that I noticed the spark across the relay contacts. The relay actually started switching when the mains had fallen around 80 Vac, not at the full 340-ish V peak of the 240 V mains.
Note that the microprocessor PCB was on one side of an excellently earthed, large (maybe 800 x 600 mm) 4 mm-thick steel plate. The relay was on the other side of the plate, about a foot lower and amongst more earthed steel. All that earthed metal didn't stop the problem.
We needed the complete disconnection of a mechanical relay for other reasons so I designed a board to put an SSR in series with the relay, and therefore with the mains to the motor. The board controlled the timing sequence of the relays (ON was: relay on, wait 10 ms contact travel, SSR on; OFF was: SSR off, 20 ms for mains to cross next 1/2 cycle with margin, relay off). This solved it and we made at least 20,000 units of that machine with no more problems.
Months later, we saw another freeze on the microprocessor when an insulated metal part picked up a large static charge then later touched the earthed steel metalwork. The sparking/touching and discharge into earth knocked the microprocessor over every time. By then, we were on the lookout for it, and earthed the metal part, stopping it charging and fixing the problem. We used a static discharge gun to prove it all, removing and reattaching our earthing strip fix and watching the problem come back and go away.