A shower that gets hot whenever someone flushes a toilet is a sign that you have an old form of plumbing that isn't properly regulating your shower's water pressure.
Let us explain a little more...
What's happening when you get a blast of hot water
To achieve your desired temperature, your shower valve is mixing hot water and cold water.
However, when the toilet is flushed, cold water is temporarily siphoned away from the shower as the toilet refills. This makes the mixture of water coming out of your showerhead much hotter.
Not only is this uncomfortable, but this hot blast could burn you!
A similar phenomenon can happen in reverse if you're in the shower when an appliance that uses hot water (like a dishwasher) starts running. It can siphon away hot water, shooting a frigid blast of cold water your way as a result.
How you can fix it
Here's a list of things you can do to eliminate this problem, starting with the easiest, least expensive, and less drastic and going to the more expensive and complicated.
Don't use your toilet when someone's in the shower.
Really, this is the simplest way to fix the problem. But if you have a large household, this might be easy to do. In that case, one of the other options may help.
Slow down your toilet's refill valve.
Slowing down the toilet's refill will make the flush less noticeable for those in the shower, but it will make your toilet take longer to refill. Alternately, you could install low-flow toilets.
Install a thermostatic mixing valve for your shower.
A mixing valve monitors the water pressure of the hot and cold water coming into the shower. So, if the cold water pressure drops (like when a toilet is flushed) it will also drop the hot water pressure. This helps keep your shower at a constant temperature.
Fix your plumbing system.
A professional plumber can solve the problem in 2 ways:
Both of these options are much more expensive, but if your home is older and you have other plumbing issues, this might be something you want to tackle along with the other plumbing fixes.
Troubleshoot more toilet problems: