After assigning a Pokemon to a gym, trainers no longer retain control of that Pokemon while it's in the gym. Instead, the defending Pokemon is controlled by a rudimentary AI in battle.

Player-controlled attackers and AI-controlled defenders fight under a different set of rules:

Mechanics Attacking Trainer Defense AI Lineup Up to 6, in order of trainer's choice Up to 6, in the order they were placed into the gym Maximum HP Unchanged Doubled Energy capacity 100 100 Initial attack At 99.3 seconds on the game clock At 98.4 seconds on the game clock Fast Move duration Unchanged +1.5~2.5 seconds Charge move duration Unchanged +1.5~2.5 seconds Charge move usage At attacker's discretion 50% chance when energy is sufficient, decided at the beginning of the previous move Energy gain per HP lost $$ceiling(HPLost/2)$$ $$ceiling(HPLost/2)$$ Switching Yes, with a short cooldown No Dodging Yes, with a short cooldown No

While attackers benefit from using high-DPS fast moves, defenders benefit more from using slower, heavier-hitting fast moves. The doubling of defender HP also encourages choosing defending Pokemon with a higher HP stat.

These mechanical differences mean that defenders deal less damage, but they can also tank more damage in battle. The defender can also potentially use more charge moves, since over a round of battle, they will be gaining more energy from damage received. The defender effectively has access to another HP bar's worth of energy in a full battle. This can have devastating consequences, such as a defending Snorlax being able to fire off 3 Hyper Beams in one round of battle.

The research of identifying certain battle mechanics (also applicable to raid battles) can be found here.