Although there are several reasons why you have a rotten egg smell in your hot water, the most likely cause is the sulfur bacteria (SRB) in your hot water tank. This bacteria feeds on sulfur and produces hydrogen sulfide gas as a waste product. When the gas dissolves in the water, it gives it that characteristic odor of spoiled eggs.
Another common cause is the chemical reaction between your water which has high levels of magnesium content and the magnesium anode rod in the water heater tank. In some cases, the chemical reaction can be stopped by removing the anode rod. However, this is not recommended since without it the water heater won't have any protection against corrosion.
To get rid of the bad odor, you’ll want to contact a plumber to flush and disinfect your tank.Doing so will remove the bacteria and particles that create hydrogen sulfide. During a water heater flush, a plumber can replace your anode rod if it is corroded to prevent the smell in the future.