A gym is a place where Pokémon trainers train their Pokémon. Just like real life gymnasiums, where one goes to build physical strength, Pokémon gyms are places where trainers can go to sharpen their battling skills and where their Pokémon gain experience.
Often specializing in a particular type, gyms create an environment which allows trainers to test both their skills and Pokémon against those of others. The most powerful trainer in a given gym is called the gym leader, who is revered by both the lower-ranking members of the gym and local fans.
Defeating all gym leaders for each region enables the ability to find legendary Pokémon on the maps.
You can track your progress from your profile by checking your obtained badges. In addition, there is a row of ribbons which represent the completion of each region. In the past, elite 4 members, champions, battle frontier brains, and battle maison members had to be completed for all legendary Pokémon to become obtainable but is no longer the case after a v4 update.