How was that trait picked out by natural selection?
Thank you.
mslxl
The genes in individuals that die stinging are shared with other individuals that benefit from the lessons learned by the stung predator.
Recall that stinging insects have bold markings. This is to train their predators that they are not safe to attack.
Colony insects may be thought of not as individuals, but as a single organism, since most members are not reproductive. Worker bees have every justification to sacrifice their lives for the hive since they do not reproduce, themselves, but will give their lives in defense of the colony (specifically, the queen and male drones). Their genes for stinging, dying while stinging, and being painful memories in their predators, are in the queens they are defending.
Think of individual bees as comparable to individual cells in humans. We will, if necessary, punch hard an enemy, and kill a few cells in our knuckles as a side effect, to defend our reproductive survival. The OP question would be like asking, "How is the trait of cell death picked out for natural selection?" It benefits the organism, or the hive which works like a single organism.
For non-colony stinging insects, it works similarly. Think of it as survival of the gene, not survival of the individual -- a modern refinement of Darwinism.