I think it's a free for all. I just won my first gym battle and by the time I healed my main Pokemon and put him in the gym it briefly turned yellow then gave me an error bar at the top and it switched to red.
The occupier was low level but I had to reboot as the gym battle glitch happened.
By the time I got back in someone else from yellow team captured it and I was able to add my own Pokemon and take gym lead.
It seems like taking control of a gym is extremely chaotic and unpredictable.
I noticed that a lot of the gyms around me with 1300cp Pokemon were going down and being replaced by teams with less than 500 Cp. I understand why now. Once it's open the vultures come out.i think they need to rethink this system.