Magic mushrooms are named for their mind-altering effects on human consumers.
The liberty cap is the most famous example, but a wide range of other species also produce psilocybin, the psychoactive compound that interferes with the signals between nerve cells.
These fungi are not closely related, suggesting that they have evolved the ability to manufacture psilocybin independently of each other. What they have in common is that they grow in habitats with high numbers of fungus-eating arthropods.
Psilocybin messes with the minds of insects, too, but rather than inducing hallucinations, it reduces their appetite.