The schematic is OK as far as it goes, but it could use two things.
First, a noise filter on the 5 V input so the relay doesn't try to respond to millisecond noise transients.
Second, some hysteresis. This is a little positive feedback around the comparator to immunize against noise in a different way. A comparator is a linear amplifier running "wide open", so its output is intentionally saturated against either the high or low voltage rail. but if the two inputs are almost exactly equal, like 1 microvolt apart -- which they will be as the 5 V input transitions across the reference voltage -- the comparator will amplify this by 1 million (or whatever its open loop gain is) and the output will be a volt or two instead of saturated. Whatever noise is on the input will be amplified, and the output will be a noise burst that can drive downstream circuits crazy. The solution is a large value resistor from the output to the + input. Start with 100K in your case. Now when the first noise tip causes the output to start to transition, the positive feedback shifts the reference voltage. If the input moves downward 1 uV to cause the output to change, it now must move up around 50 mV to cause the output to change back. The circuit now has 50 mV or "noise immunity". I'm winging rough estimate numbers here, but that's the idea.
In post #1 you said you wanted the circuit to latch once there was a brief 5V dip. To do that, replace the 100K hysteresis resistor with a diode. Now the reference will shift from approx 4.5 V to around 9 V, something the input never can overcome. The output will stay high until the circuit is reset. You can add a reset button as a dead short across the 10K pot.
To make sure the circuit powers up in the non-reset mode, add a 10 uF capacitor across the pot so the reference voltage comes up to its threshold value later than the input.
ak