For all that Darwin did, Evolution as yet has no explanation for puzzling animal behavior.
Social insects provide some of the most fascinating examples of altruism in the natural world, with sterile workers sacrificing their own reproduction for the greater good of the colony.
That isn't the case with all insects - in some cases, there is a very real battle of the sexes going on, even in their larvae.
It's been generally believed that sterile 'soldier' larvae act in positive ways, by protecting them from attack by other species of parasitoids.