I suppose that among the readers of this blog interest in the biology and biochemistry of psilocybin may outweigh that in its recreational value (but I am not taking bets). Anyhow, there is something to report on its biosynthesis and, less so, on what's in it for the mushroom that makes it.
Psilocybin, as you probably know, is a psychoactive compound produced, among others, by about 200 kinds of "magic mushrooms," a name given to members of the genus Psilocybe and other fungi that are found nearly worldwide. First brought to the attention of the West in the 1960s from their ritualistic use in Southern Mexico, psilocybin and related compounds have been used for recreational use as well as in psychiatric research. They are listed among the controlled substances, a practice that has been challenged. Of recent, there has been renewed interest in using this compound for treatment of addiction, depression, and pain. Chemically, psilocybin is a derivative of tryptamine and is structurally similar to the neurotransmitter serotonin, which it mimics in activity. It is made as a prodrug and is converted in the body to the active form, psilocin, by dephosphorylation.
Psilocybin is made from tryptophan through a well characterized pathway. The enzymes required for its synthesis, perhaps not surprisingly, are encoded in a gene cluster. Why do so many unrelated mushrooms make these compounds? In the words of the authors of a recent paper, "Spotty phylogenetic distributions of fungal compounds are sometimes explained by horizontal transfer of metabolic gene clusters among unrelated fungi with overlapping niches." Nice, but does such information tell us why mushrooms make such compounds? Guesses abound, most of them relating to the fact most mushrooms, the psilocybin-makers included, fall prey to voracious insects. Is making psilocybin a way to interfere with the neurotransmission mechanism of the insects? Recent work says no – flies growing inside Psilocybe cyanescens, a psilocybin producer, make viable larvae. Thus these insects are apparently indifferent to the compound.
This is in keeping with the experience with the entire field of specialized metabolites (formerly referred to as "secondary" metabolites but the current consensus is moving away from that designation since these molecules are anything but "secondary") where the purpose for why they are made is often obscure, the reason being that not making them is usually not deleterious, at least not in the short run and in the context of pure cultures. To stay with mushrooms, the lethal amanitins produced by a number of poisonous mushrooms are not likely to be made to ward off mushroom-eating animals. I say this because symptoms of eating such mushrooms do not usually appear until many hours if not days after ingestion. Thus, it seems unlikely that mycophagous animals can put two and two together to remember what they ate such a long time ago. Specialized metabolites are often highly useful (take the example of antibiotics) and interesting. But why they are made is more often than not elusive and unfathomable.