I thought the caterpillar was being parasited by wasps... Yes, it happens quite frequently in nature... And when the wasp larvae emerge, they are covered in what the caterpillar would have normally used to build itself a cocoon, because otherwise they would be parasited by other wasps... That parasite parasitic wasps. I swear I'm not kidding.