They are a defensive mechanism, which dissolve in water, and they are distasteful to most animals who would prey on rhabditid worms.
The defensive mechanism of rhabditid worms, which dissolve in water and are unpleasant for predators, is a key aspect of their survival.