I think the main explanations are that a lot of them have been evolved in plants and animals to deter and confuse predators / animals that would eat the plant. It seems incredible but is no more incredible than the millions of other plant-animal relations that have evolved over spans of time. For example the relation between the shape of beaks of birds that drink nectar from flowers with a matching shape. The psychedelics as a key in the lock of the receptor would not be too different from that. A difference is that bird beaks still tend to work if they are a little bit different, but with chemicals often not so much. Still it wouldn't be too far off and would require more time.
Some other psychedelics / psychoactives in plant may exist from a combination of coincidence and similarity between biochemicals, for example indoles found in plants and serotonin in animals. How all of that is tuned into each other over the history of life is incredibly complex and wonderful.
But I don't think it's helpful to look for special purpose, like some intelligent design thing. Ironically that is not an intelligent theory.