A warm shower suddenly freezing or scalding is an unpleasant surprise every time. Fortunately, there's no need to speculate why, because these are most likely the guilty parties.
Your shower's pressure balancing valve maintains the harmony between hot and cold water, but when it malfunctions, a hot-cold dance of the temperature is the result.
If your shower starts warm, then goes cold when a sink turns on, the shower cartridge is likely worn out or damaged and can't handle the pressure of several appliances.
It could also be a circuit breaker that keeps tripping and severing power to your water heater, most likely thanks to a faulty breaker or overloaded circuits.