Bees are some of the most organized and evolved insects in the world. Not only do they live in a large group, obeying a strict hierarchy and doing each their own thing, contributing to the life of the hive, but they also know how to communicate with each other, communicating the location of food.
Some species of insects have a special organ for laying eggs, which is called the ovipositor. Insects use it to lay eggs in the ground or deep into the bark of trees. In the case of wasps and bees, their sting is simply a modified ovipositor, to which the poison glands are connected.
Wasps, unlike bees, feed not only on plant nectar, but also on other smaller insects. They are a kind of predators, and this determines, among other things, the differences in the purpose of the sting, as compared to bees.
Unlike predator wasps, bees attack defensively, so they use the sting very rarely and it is not as perfect as a wasp's. The sting of bees is serrated, like a harpoon, while the sting of wasps is smooth. The serrations do not get stuck in the chitinous plates of insects attacking the hive, but they do get stuck in the elastic skin of beasts and birds. In an attempt to free itself, the bee damages the internal organs connected to the stuck sting and, naturally, dies. If, however, the bee manages to free the sting without damage, nothing prevents it from attacking again and again until its glands run out of venom.