I had to do a little research on cocoons to find out how long they actually last.
I guess the average is about 2 weeks.  Think about that…
A caterpillar dissolves into mush.  Then in about 2 weeks, the mush reforms into a completely different creature.
I can’t even imagine how evolution made this a thing.  Why couldn’t the caterpillar just stay a caterpillar?  Or why couldn’t the butterfly be a butterfly right from the start?
My guess is that it’s just a delayed gestation.  It ultimately is a butterfly that got to explore the world while it was still effectively an embryo.
But what do I know.  I draw cartoons.
John Vogel