There are many things that can cause hydrogen sulfide contamination, all are preventable:
Too much sulfite, usually the result of grapes being dusted with too much sulfur during the growing season.
Lack of proper nutrients (nitrogen, yeast hulls) during fermentation.
Yeast combining with various forms of sulfur.
Bacterial contamination due to poor sanitation techniques.
That being said, here are the things you can do to prevent H2S contamination:
Add proper amounts of sulfites to wine.
If making wine from scratch (not from a kit), add a proper amount of yeast nutrient prior to pitching yeast.
Use proper yeast for the wine you’re making, and make sure it has not passed the expiration date or gotten too hot in storage.
Maintain sanitary conditions for your equipment and must (especially prior to pitching yeast).