For hundreds of millions of years, plants have faced a problem with no easy solution: they cannot run, hide, or bite back. So they evolved a chemistry set instead. Insect herbivory became one of the great driving forces of plant evolution, and plants answered it with an arsenal of secondary metabolites — toxic compounds like alkaloids and terpenoids, manufactured specifically to poison the animals chewing on them.
These are not accidental byproducts. They are costly molecules built to do a job. And the reason so many of them mess with minds is brutally elegant: to be effective, a defence chemical has to interfere with the inner workings of an animal — and a huge number of them evolved to jam neuronal signal transduction, the electrical-chemical messaging of the nervous system itself.
A toxin that scrambles a nervous system stops a caterpillar mid-bite. From the plant's point of view, psilocybin, nicotine, and caffeine are nerve agents tuned to disorient whatever dares to eat the cap or the leaf. The dizziness, the buzz, the hallucination — what we package and sell as a "high" — is the plant's poison doing exactly what natural selection designed it to do.