Try a hot water faucet near the hot water heater, something other than a shower control. Maybe a laundry tub. Does that have the same problem?
Do you have a tempering valve? That will be a little valve with hot and cold water coming in, and an outlet to your hot water line going out. It will usually have an adjusting feature on it. You will find it, if there is one, by following the hot water line from your water heater for a short distance.
If you have the same problem with a separate faucet, then maybe the dip tube in the hot water heater has failed. That is the the device in the heater that puts the cold water at the bottom of the heater.
It could be a temperature control in the shower valve sticking, or responding slowly to variations in pressure or temperature.