How exactly does a caterpillar morph into a butterfly?

At the very least, it evolved twice – amphibians employ it because they have to lay their eggs in water because they need water to flush away embryonic piss. More advanced vertebrates use other solutions, involving processing urea into uric acid, which can then settle out in the egg (reptiles, dinosaurs, birds, and monotremes), or letting the mother take care of the problem (placental mammals). (I don’t know about marsupials.) Insects, on the other hand, use metamorphosis to help solve the problem of growth with an exoskeleton; a caterpillar can molt much more easily than a butterfly could.

In both cases, only the actual metamorphosis process had to evolve. Frogs, having fish ancestors, have no great problem starting life as fish. Insects, having worm ancestors, have no great problem starting life as worms. (“Ontogeny recapitulates phylogeny” is only partially true, but it is partially true, especially when it happens to be useful.)

Thank you for your explanation, which for me at least, deepens my understanding this complex process. While the details always seem to be more miraculous than natural, the light bulb in my head went off when you described frogs from fish and insects from worms.