That's a good question. As I already discussed elsewhere, both because animals eating the fruit helps to disperse the seeds and because we have been very involved in selecting for fruit we can eat, it is not too surprising that there is a lot of tasty and healthy fruit. But then the question arises, why is there any poisonous fruit, and berries in particular?
I can think of three good answers to that question:
1) What is it that the plant would really WANT, if it could think about it? It does want some animals to eat its fruit so that they can help spread the seeds around. But, it depends on the animal. Some animals might grind the seed with their teeth or gizzard. Some animals might have such strong stomach acid that the seed gets digested. In either of those cases, the plant would NOT want the animal to eat it. So, wouldn't the plant love to have a way to have the fruits be popular with animals that will pass the seed unharmed through their digestive track but NOT popular with those that will destroy the seed?
Actually, having a seed that contains poison in its interior would be the perfect way to achieve that. If the fruit is tasty and wholesome, but the seed itself is poisonous, then the plant gets the benefits of having its seeds spread by some animals without the disadvantages of having its seeds wasted by others who will just devour it.
I'm no botanist, but it seems to me that this must be very common. I know that the chokecherry is used by people (for making wine, or the traditional Native American dish, pemican) but that they are very careful to avoid using the seed. In nature, there are many birds who eat chokecherries (and presumably pass the seed out in their droppings, prefertilized and planted!) while cows (who chew the seeds) are known to die from eating it.
2) Another situation is that fruits may be poisonous only during some points in their growing cycle. There are some berries, I believe, which are poisonous before they are ripe. Again, this benefits the plant by making certain that the seed is not wasted by being in a fruit that is eaten before it is ready to be planted.
3) Finally, note that some fruits are poisonous only to some creatures. To others, they may be harmless or only a minor irritant. This can depend on genetics (e.g. deer eat poison ivy and have no trouble with it) or simply because of size. The situation of size, in fact, helps us understand why a plant might benefit from having something poisonous in its fruit. If a bear eats some berries, the "poison" might irritate the gut and make the animal pass it more quickly but not cause the animal any serious harm. The same fruit could put a human (smaller than a bear) in the hospital. (For an example of this, check out Rhamnus cathartica.)
Anyway, those are my thoughts. If you see some flaw in my logic, please let me know. But, I think these are at least three reasons that plants might benefit from having poisonous fruit. Anyone see any others?