That was almost certainly a horsehair worm (Nematomorpha).
Juvenile horsehair worms parasitize insects such as praying mantises, crickets, grasshoppers, and cockroaches. Adults live free in water.
Long, thin, dark brown to black worms that can be many times the host’s body length.
The worm develops inside the insect and manipulates host behavior to seek water, where the worm emerges. Pouring water on the mantis mimicked this trigger.
The worm consumes host resources but usually leaves the insect alive until emergence. The host often dies soon afterward due to damage and energy depletion.