Trainers battling in Gyms are put in separate battle groups.
Issue description:
For Trainers entering a Gym battle: Trainers attempting to battle a Gym defender are entered into separate battles and are not collecting friendship XP because they are not battling together.
For Trainers defending a Gym: Because the Gym battles are happening simultaneously, the defending Pokémon faints more quickly.
Issue status: Resolved in the next release