Some berries taste great but some berries poison you. Real puzzling isn't it.
That's not the purpose of the berry. The purpose is just to ensure the survival of the seed. In drought-stricken environments, the seed is probably better off keeping its shell of water and fructose until it can form a root system.
For other plants it may be advantageous to be poisonous to one species and not another
Birds tend to travel farther during any given time period than (typically terrestrial) mammals do, making them better at spreading seeds over a wide area. So it's evolutionarily advantageous for plants to optimize their fruits to be eaten by birds instead of mammals.