The hose connected to our washer came out of the drain pipe last night and caused a huge mess, 1" of standing water in our basement, and that's with my wife catching it early. Is there a way to secure the hose to the drain pipe to prevent this from happening again? Right now it's just in there and hanging by the ridges of the hose itself, picture below.
I would run cable ties around each of the supply lines in a figure eight arrangement. They're easy to remove should you need to and non-destructive.
There's fairly little force at play here--the rarity of such a disconnection demonstrates that. You only need a slight resistance to lifting to solve the problem. Just don't pull anything so tight that you kink or stress the supply lines.
You could get some plastic hanger strap and attach it to the wall perpendicular to the hose using 2 drywall anchors and screws.
Just make sure you don't penetrate your water lines.
Another idea would be to place a block of wood on top of the hose and butt it up against that enclosure's ceiling. This would prevent the hose from jumping out.
You can use a hose clamp/clip specifically designed for these hoses.
Doing a search for "washer drain hose clamp" brought up some options to try:
And doing other searches shows that some drainage hoses have these built-in.
The ones I've seen have a tab with at least one hole in them so they can be attached to something, like an anchor or screw in a wall.
Besides being attached to something, the advantage they give is that the force pulling them out would get redirected to pushing it into the wall, due to the hard radius of the plastic clip. Once it hits the wall, the curve causes the force on the hose remaining in the pipe to go sideways into the pipe, rather than up to drag it the rest of the way out. Or the wall box gets in the way and prevents the rest of the hose from coming out.
I have one of these on my own washer and it's pretty difficult to pull it out when I want to do it on purpose. Mine has the large radius to prevent kinking the hose and turns around far enough to practically clamp itself onto the wall without any extra hardware, similar to the last link I supplied.
*FYI, I'm not recommending brands or suppliers. The ones I chose to link were simply the easiest to find and had were different types to show different options available. Also, you'll need to make sure that the part actually fits your make and model of washer.
One option is to place something in the space the hose wants to move in the event it is trying to lift out of the pipe. You could cut a block of styrofoam to span the inside height of the box and straddle the pipe, and you slip it in at an angle. (This is similar to the use of a wooden or metal rod to block a sliding door or window from opening.)
With denser foam or a wood block, you could use a smaller piece and attach it to the back of the box using adhesive Velcro.
If you have enough excess hose, you could add a rigid hose guide around the end of your hose which would guarantee about 4 inches of the hose will be in the pipe at rest, and about the last 10 inches of the hose cannot flex in a way that makes it easier for it to slip or flop or "jet" out of the pipe. Further, some models of hose guide have attachments which would handily support affixing them to the box with a screw or the surrounding hoses with nylon zip-ties as in other people's answers.
Here is an example for visual reference: https://www.amazon.com/Supplying-Demand-WH41X10133-Compatible-AH1021929/dp/B07VB55R9Z