This can be an unsafe situation to have a sudden burst of very hot water in the middle of a shower, and you need to have a licensed and insured master plumber check this out as soon as possible. Do not use the shower until this problem is resolved. It could be an issue with your water heater and/or mixing valve, or the way your system is set up. Either way, it needs to be handled by a professional plumbing company in your area. Ed Del Grande, is a three-time Master Plumber, GBCI LEED green associate, and contractor. He was born and raised in a family-owned plumbing business. He holds three current Master licenses in pipefitting, fire protection, and plumbing. http://eddelgrande.com.

The water heater has nothing to do with the supply of uneven water temps. It will gradually decrease in temp as the tank begins to run out of water.

In the shower valve is a device that controls the water temp by mixing the cold with the hot to deliver a constant temp that is set by the handle. If that temp goes up and down its the faucet control that is starting to fail. With modern anti-scald valves this device is set when installed to prevent super hot water from ever exiting the shower or tub faucet.

What make of faucet do you have? Do you know the age? Single lever I would assume? Or does this have a single lever that turns the water on, and another lever that controls the temp? in any case the internal valve assembly needs to be fixed.