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.
Pokémon Gym
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, elite 4 members, champions, battle frontier brains, and battle maison members 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 confirmation box on your private profile page that displays if you have met the requirements to enable legendary Pokémon on the maps or not.