It's hard to believe that a horse can get stuck - or cast - in his horse stall. However, this is a real danger. A horse is said to be cast when he has lain down or rolled and managed to position himself with his legs so close to the stall wall that he can neither get up nor reposition himself to roll the other way.
Most horses panic when they find themselves cast in their stall. They will struggle violently, banging their legs against the wall (making quite a lot of racket) of the stall and sometimes banging their heads.
The horse will need your assistance, but you'll need to do this in a way that's safe and that will get the horse repositioned as quickly as possible.
First, get help. Horses are heavy. Even if you think you're strong enough to move the horse by yourself, it's always wise to have someone else there when you go into a small area with a panicked horse.
Always stay behind the horse's back, never on the same side as his legs/feet. If the horse is positioned up against the side of the stall where the door is located, open the door and talk to the horse, making sure you have his attention. Once you think the horse is paying attention to you, stroke him lightly to make sure he really does realize you are there, and to see if he's going to react violently to your touch. Then get to the belly and climb over the horse as quickly as you can.
If the horse is not directly against the door, still enter with caution and make sure you have the horse's attention before getting too close. If he does manage to push himself onto his back and roll over, you could be within reach of his legs.
The first thing to try is to move the front end of the horse more toward the center of the area. The horse will be facing the wall and either lying flat on his side or, if very close to the wall, may be on a bit of a tilt, with his legs folded against the body.
Never pull or drag a horse by pulling on the halter. You can do serious damage to his spine. Position yourself at the middle of the horse's neck, grab hefty handfuls of mane, and pull straight back toward you.
After the horse is back far enough to be able to fold his legs underneath himself and roll onto his belly, get out of the way, preferably out of the stall. Once the horse has control of his front end restored, he will often be able to figure out how to flex his hind legs and get up.
If he can't, you'll need to pull his hind end free too, using his tail. Keeping the tail aligned with the horse's spine, pull back to slide the horse away from the wall. Don't pull up, as if trying to lift the horse.