MCU freezes when power disconnected from attached HMI
You need to carefully evaluate how the relay is hooked up. There are two big issues with the relay that can definitely cause an MCU's software to go out to the weeds. This comes from internal disturbance of the MCU execution due to out of spec supply lines or out of spec voltages present on GPIO pins.

The Relay Coil

Relay coils are inductive loads and can cause spikes to occur, particularly when the relay coil becomes un-energized. But supply and GND surges and spikes can also occur when the relay becomes energized, because in some cases the change of current flow that occurs at time of switch on can be significant with a low resistance relay coil. 

Some things to deal with and consider:


Make sure there is a flyback clamping diode across the relay coil.
Consider to operate the relay off a separate power rail than the MCU and then buffer the drive to the relay coil through a buffer transistor that isolates relay coil current away from the MCU.
If a completely separate voltage rail is available with isolated GND consider running the relay coil off that and isolate between the MCU and the relay with an opto-coupler. 
Verify that you have sufficient filtering capacitors on the MCU supply rail.
Ensure that there is proper high frequency bypass capacitance right across the MCU PWR/GND pins.
Make sure that there is not an bad circuit design on the GPIO driving the relay that taxes the pin drive capabilities beyond the spec ratings.
Look carefully at how the actual connections to the relay coil are made. Make sure that there are not careless long wires that themselves can create noise coupling to the rest of the circuit. 


The Relay Contacts

Relay contacts can be a nightmare in the amount of noise generated. This is especially true when high voltage or high currents are switched. Here are some of the things to consider taking a look at:


Make sure that whatever wiring is associated with the relay contacts is routed away from the rest of the MCU circuitry. 
Sometimes it is necessary to add snubber circuit components across the relay switch contacts to reduce the amount of noise generated when contacts open and close. 
Relay contacts are known to bounce and cause multiple opening and closing of the load switching. In some cases it may be possible to select a different type of relay to reduce this effect and thus reduce generated noise.