Usually, the spa sits above the water line of the pool so if something goes wrong the water from the spa will drain out, but as to the cause as for why that would happen, the most common would be a check valve. There’s a check valve that helps keep the water in the spa and sometimes debris will get stuck in the check valve or the check valve will just go bad. In most cases you can open up the check valve and take a look at it, there are flapper style valves, you could just replace the flapper, or you might have to replace the whole thing. That’s the number one cause.
Some other reasons why there are diverter valves that control the spa suction if that’s left open or even partially open when the pump shuts off. It’s going to drain back out to the pool.
Within those diverter valves there’s a gate, and over time that gate could wear out, or the seal on that gate could become damaged so you might have to replace the internals in that valve. Another reason could be a bad actuator; maybe the actuator died when the gate was still left open on the suction side for the spa, so you’d have to replace that actuator.
Finally, you could have an air leak. Normally if a pool system is perfect, it’s sealed so that the water won’t drain out from the pump or anywhere else when it shuts off, but if there’s an air leak, it loses that seal and everything floods back to the pool. That’s another reason why your spa could drain out.