Here is wikipedia page containing a list of plants used in herbal medicine. One might first want to argue that many of them actually do not have any medicinal/beneficial effect on heatlth. I think we have evidences for quite a lot of species that they actually mimic drugs. For example Filipendula ulmaria is rich in acetylsalicylic acid (aspirin). So I hope, you'll agree to assume that there are quite a lot of plant species that contains substances that are usable in medicine. If there are many of them, my question is:
Evolutionarily speaking, why are there so many drug-like plants?
At first, I woud say that an allele for producing a substance which is beneficial for a predator should not get fixed in the population! so why are they so numerous to have medicinal properties?
Here are some (intuitive, unclear or far-fetched, non-exhaustive and non-exclusive) hypotheses I can think of:
Because plants want their seeds to get ingested in order to propagate
Is it because there are so many substances that affect our homeostasy that many plants are toxic and many are healthy just by chance. Containing healthy substances are not adaptations but by-product of evolution.
The substances that are beneficial for us actually evolved to repulse predators. These substances are toxic at high dosage and therefore are efficient against predators that are small or eat a lot of plants (herbivorous). These substances at low dosage might actually have a benefical effect. For example a substance that make blood thicker is very toxic except if you eat just a bit of it while bleeding.
We (primate or whatever taxon you want to consider) evolved in order to get advantage of the surrounding envirronment. Sbstances that were neutral became beneficial. The advantage of being sensitive to various products cause that, by chosing our food source, we can heal. Therefore, by evolving sentivity to various substances, our behaviour can act as a reinforcement to immunity (and other anti-illness system). If this is true, we might expect that the frequency of presence of a plant species affect the probability that out homeostasy get affected when eating it.
Lineage selection. Lineages that produce substances that are active in predators body in a way or another are undergoing many various selection forces because of these substances. Therefore they get a higher speciation rate than other lineages.
Keeping some non-herbivorous species in large population size (by helping them) is the best way to keep herbivorous species in small population (because of territory competition, predators relationships, etc... )