How does a caterpillar turn into a butterfly or moth?
This is not easy to explain. Broadly, inside the chrysalis the caterpillar changes clothes and turns into a butterfly.
An esoteric explanation: Inside the chrysalis the caterpillar structures are broken down chemically and the adult's new structures are formed.