If your answer is "it's a random mutation" then that settles the "why" question permanently. Why all this idle speculation about bee's stingers, then? It was a random mutation, and it survived, done.
Every single part of an organism goes through a recombination/mutation process countless times, the stinger evolved to be what it is today over a very long time and it's cool to study why it ended up the way it did. Tells us about their environment and history and evolutionary pressures, survival is a result of the random traits being successful in their context in specific ways.
You might be interested in this concept: