The general answer you’ll get if you ask people is that it was probably through trial and error or just sheer luck. But this is a very unlikely theory. It would probably take millions of years to find all those plants that cured every kind of illness. Most likely humanity would have given up as soon as they saw that this experimentation killed more people than it healed. Our ancestors had a very different view of the natural world, their relationship with nature was as intimate as a child to her mother. Their senses were sharper and their knowledge and memory vast, compared to those who now rely on money for food and google instead of memory. They would have the knowledge of every smell and taste of each plant and the effect they have on the human mind and body. They would recognise the qualities of a newly discovered plant by comparing its qualities with what they already knew of other plants. But this does not explain how they found specific medical properties of plants in the first place. One simple answer may be that they gained this knowledge through shamanistic techniques, by journeying and communicating with the spirits of the plants the shaman can discover the properties of plants. As they most probably had a much stronger connection to the spiritworld, the world where all organisms and all things can communicate.