The usual cause is a type of bacteria that comes in with the water. It’s called sulfate reducing bacteria but could be iron reducing bacteria also. In some cases it will be manganese reducing bacteria or a combination of the three but SRB is most likely if you have an electric water heater with a magnesium anode rod; the newer the more probably. Another cause is a trace amount of H2S in the water that migrates to the most infrequently used fixtures.
Sanitizing the heater with bleach will stop the problem but only temporarily, but turning the temp up to 140f is a permanent solution as is killing the bacteria.
Quality Water Associates