there are many species of fungi, from mycelium to the actual mushroom with the cap... in the soil, there are mycorrhizae, which are fungi that live in symbiosis with the roots, protecting them and exchanging nutrients. so if the fungus appears as a whitish film on top of the soil, it's good; those are the mycorrhizae at work.
if, however, actual mushrooms are growing a few cm tall, you have 2 problems. too much watering; if you let the soil dry well between waterings, the mushrooms won't grow due to lack of moisture. the second problem is where the mushroom spores are coming from? probably poor storage of the soil has caused "contamination"; it could also be anything, even spores that accidentally fell from your clothes. the solution is to let the soil dry well, remove 2 or 3 cm of substrate, and replace it...