A slight change in mindset can be the difference between winning and losing. You wanna think about what your opponent is going to do. Mostly, it's going to be switches.
From what I can tell, the Gym Leader AI switches when;
-It can do more damage with a different pokemon, based off of its own attack/special attack
-Another pokemon they have, has a super effective move, while the one on the field does not.
-You have a type advantage, and they have a pokemon that's normally effected/resistant to it.
Use this knowledge to help predict switches. It's not 100% foolproof, however, but that's what keeps this interesting.