A Gym Leader is the highest ranked Pokémon Trainer within a Pokémon Gym. The prominent role of a Gym Leader is to test the challenging trainer to see if they are worthy or not of going up against the Elite Four (named Pokémon League in the animé). If a challenger beats the Gym Leader of a Gym, they are awarded a Badge as proof of them winning. Once the trainer has earned all 8 Badges in that region, they may then go on to challenge the Elite 4.
However, a Gym Leader is also responsible for the maintenance and the upkeep of the gym they lead. this is a rather hard job as each gym is tailored to represent the leaders specified type, and provide the best environment to train, battle and keep their POkemon in. (Eg. A water type gym will typically be have pools of water, or be water based with it's appearance). Another role a Gym Leader teachers new trainers how to battle, something which both Morty and Roxanne have said. Within the games the trainers must over come several obstacles in order to reach the gym leader, often causing them to battle trainers in the gym. Apart from leading the gym, gym leaders typically do something outside battling, often something to do with a towns speciality or tourist attraction. It's not uncommon for Gym Leaders to leave their Gym without notice (Something which Blue, Giovanni, Jasmine, Wallace and Volkner have shown to do), some have even left to challenge other Gym Leaders and/or challenge the Elite Four.
It is still unclear how a Gym Leader attains their position as Leader of their Gym, however it seems to vary from Gym to Gym, some attain it through blood line, some are self appointed, some are the founders of the gym, and some are chosen by other members of the Gym in question. It's even been shown that the trainers send out their Pokemon and let them fight without giving them orders, this has only happened in the Manga however.
Related ThreadsMy Gym Leaders(5th Gen idea) - last post @ Mar 23, 2013
The Gym leader Game - last post by @ Jul 21, 2007
favorite/least favorite gym leader in X and Y? - last post by @ Dec 1, 2013
The Pokemon League, Gym Leaders, Elite Four, and More. - last post by @ Aug 23, 2010
Gym Leader/Champion Levels - last post by @ Oct 19, 2013