Horsehair worms parasitize arthropods in order to complete their life cycle. The larvae live in bodies of water like puddles, ponds, or streams until they are ingested by arthropod hosts who were just searching for a drink. Over the next several weeks or months (depending on the species), the worms steal all of the nutrients they need from the host, maturing and growing to lengths upwards of 2 meters. Eventually, the parasite affects the host's brain, driving it to seek out a body of water. Once the host hits the water, the adult horsehair worm erupts through the host, ready to finish its life and reproduce before it dies.
You can check out the adult horsehair worm completing its life cycle and leaving the mantis as soon as it makes contact with water.