Air and surfaces are filled with random mould spores and bacteria. If they touch your beverage (which is by definition full of stuff that mould loves, because yeast is a mould) then they will grow, causing off-flavours or even poisons. You prevent this by sanitising everything, and making sure that any headspace is filled with either carbon dioxide or sulphur dioxide. CO2 is produced naturally by fermentation and because it's heavier than air it settles in the headspace displacing oxygen (moulds need oxygen to reproduce). Sulphur dioxide can be added using sterilising tablets (Campden tablets). Other techniques are to reduce the headspace by adding more liquid, or marbles, apparently, and using an airlock to stop air entering.
There is nothing that can grow during fermentation in beer or wine that will hurt you. It will just taste terrible, or unplanned.
In lower abv fermentation such as kombucha or fermented vegetables. Molds can be a risk if the starting medium is not low enough ph, or high enough salinity.
Something like aspergillus flavus could poison you, although you'd notice that because it would be clearly visible as a green mould with a terrible smell & taste. I homebrew myself and agree that poisoning from ordinary brewing (not distillation) is incredibly unlikely.