Another interesting perspective is to look at it not as a more elaborate form of exoskeleton shedding, but as hatching from a very sophisticated egg.
The pupa internally "gestates" the adult as a parthenogenetic clone-child; the adult being gestated, absorbs the pupal parent's entire body for nutrients — and, crucially, the pupal parent's body allows this absorption of its entire body, producing no immune response to it, because they have the same DNA. As with a cyclic parasite, you get two different complete lifecycles, that are each born, live, and die from the same genetic program, given a different epigenetic kickstart, in a back-and-forth cycle.