The only possible reasons for why your Galvantular keeps switch out is:
- U-Turn (Move, makes Pokemon return to their trainer after damaging the foe)
- Baton Pass (Move, makes the Pokemon Carry all the stat changes whilst switching out)
- Volt Switch (Move makes the Pokemon attack the opponent then your Pokemon switches out)
- Eject Button (Item, when you Pokemon gets hit it switches out)
- Red Card (The foe holds this item. When you attack them your are sent off the battle field)
If its none of those factors then its a glitch.