If a gym leader strands you in a course and doesn't promise to come back on any time soon, then yes, they do have to pay you 500 and you can leave the course. If, however, you challenge them and they log off without you going in the course, they do not have to pay you at all. It seems like both of those times were when a leader abandoned you when you were in the course. They are required to pay you 500 then.