Moulting
Ecdysis is part of the whole process of metamorphosis. The different stages (called 'instars') and the development of new 'apparatus' (such as sense organs) is necessary as the creature moves from one form to another. The new exoskeleton is initially soft but hardens after the moulting of the old exoskeleton.