Typically you have three way valves so you can choose to draw from pool or spa and return to pool or spa or some fraction of each. In spa mode, you should be drawing only from spa and returning only to spa, thus you heat only the spa, not the whole pool. It sounds like the return side valve didn't move to return the water to the spa although it was drawing from it, or it was working fine but when it went back to pool mode, the valve to the spa drain didn't close. So you emptied the spa into the pool.
If you didn't have automation and electric motors, it would be easy to find and fix. I haven't got a clue about all the electrical stuff for that, but usually there's so way to disengage the electric from the valve and manually turn the levers. If memory serves, it's a matter of pulling up on the handle, but don't quote me on that.
Your picture doesn't show everything clearly, but I imagine if you crawl around and study the handle positions, you'll be able to figure out which one is in the wrong spot.