I am also interested what you put in it. If the container was truly sealed, adult fungus gnats wouldn't have been able to get in there to lay eggs; otherwise they were already in the soil before cooking.
To prevent or help get rid of gnats you can use Bti (Mosquito Dunks or Bits, Gnatrol). Dunks are sold in virtually every hardware store, break them up and soak in water to apply. They also sell beneficial nematodes which attack pests like fungus gnat larvae. Others such as various predator mites which can live in the soil may also attack fungus gnat eggs, small larvae and pupal stages.
Most mycorrhizal fungi wont live (actively) without a plant host. What you may see is the mycelium of saprophytic fungi, which decay organic matter. They'll grow where ever it is moist and warm enough, given suitable organic matter.