Evolution is not conscious, no. Let’s go through your two examples:
“Some of the plants evolved to have poisonous leaves so animals wouldn’t eat them.”
“They evolved to have immunity against the poison.”
Here’s how that actually works:
- There is a valley with some plants, and some deer.
- The plants are the primary food source for the deer.
- Even so, the plants are abundant enough that some survive to flower and seed.
- Each flower has slightly different genetic information from combining the flower’s DNA with DNA from pollen from a nearby plant. These slight genetic differences are the key to evolution.
- These flowers become seeds and are scattered over the landscape.
- A bunch of random mutations happen in the plants over time (thicker stem, more water absorption, etc).
- After several generations, one happens to get a random genetic mutation that makes them create a mildly poisonous chemical.
- Deer start to avoid the slightly poisonous plants. Their leaves don’t get eaten as much, so they do much better than all the non-toxic plants.
- This makes it HARDER for the non-toxic plants to survive, because if 1/8 of the plants are toxic, the food supply’s gone down by 1/8. This means more of the non-toxic plants get eaten.
- Because the toxic plants are not getting eaten at all, and the deer are eating the competition, the new slightly toxic plants do very well and their population continues growing.
- After several more generations the toxic plants are doing SO well that they completely take over the non-toxic plants. The completely non-toxic plants go extinct.
- At this point, the desperate deer at this point are going after the slightly toxic plants. Some of the deer die to it, but some don’t.
- The deer that can best tolerate eating the slightly toxic plants will have more food available, which means more babies, each with slightly varying DNA.
- Random mutations occur along the generations that make the toxin more potent, and likewise, that make the deer more resistant to toxins. Toxic plants might get pollinated by less toxic plants, but those babies get quickly eaten by the deer that are tolerating the slightly toxic plants, and only the toxic+toxic plants do well.
- Because the deer that survive the poison are the ones that are reproducing, it becomes less of an advantage to have only weak toxin.
- Likewise, if any of the baby deer have an even better way of tolerating the toxin, they’ll have a more ample food source than the deer that can eat only slightly toxic plants. Those toxin-tolerant deer are able to have more babies, and crowd out their competition as the plants grow more and more toxic.
- Soon only deer that can tolerate eating toxic plants are left. The rest are either dead from poison or have moved on to a different area.
- Likewise, the non-toxic plants are all gone. Only plants that are toxic are left.
Now, if the plants didn’t have the deer eating them all the time, the toxin wouldn’t have been a particularly beneficial trait. Maybe a few of them would have remained toxic, but since toxins take an organism energy to create and have no other benefit, it’s unlikely that the toxin would stick around, since energy dedicated to making toxin is energy that’s not making offspring. Likewise, the deer very likely would not have become resistant to the toxins without trying to eat the toxic plants. It may pop up randomly as a mutation, but it doesn’t overly help a deer to survive, so the trait doesn’t help them out-compete their fellow deer.