Team selection determines the team color of gyms and the Pokémon you can assign to defend them. When battling a gym, you can only challenge gyms controlled by rival teams.