Attachment of muscles during molting in insects
You can find a concise answer here in a section from The Insects: Structure and Function  by R. F. Chapman, eds. Stephen J. Simpson, Angela E. Douglas. 5th Edition. Cambridge University Press.

In essence the source says that the muscle attachment to the cuticle is maintained during the moulting process, while the new cuticle is formed under the old cuticle. 


  As a result the insect is able to continue its activities after apolysis during the development of the new cuticle. The connections to the old cuticle are broken at about the time of ecdysis.


Connections to the new cuticle are formed at the same time as the old ones are broken.