I was wondering this too. If it was purely to protect the plant why even bother with the psycho active compounds? What if the plant is producing CBD's because most animals have a cannibinoid system used for hunger control? If you are a plant that uses animals to pass your seed, would it not be a benefit to the plant to make the animals hungry for more?
Almost like a symbiotic type relationship. I'll help you if you help me. In most cases where that happens both organisms give some thing to one another.
Or you could go the other way with it. The compounds are to deter animals from eating it because it makes you high. The smells also... How many animals are going to munch on anything that smells like rotting skunks? Or baby poo? But then you have smells like fruit, nuts.. ect...
I think it might be more a defense/survival mechanism.