Prestige can be considered as a gym's HP. To take over a gym owned by rival teams, a player have to decrease the prestige of the gym to 0.
How to increase prestige
1. Winning a gym battle (defense)
Prestige can be raised by defending the gym successfully. When succeeding gym defense, challenger's Pokemon get fainted.
2. Training
A player can do training in a gym owned by a team he belongs to. In the case of training, Pokemoon do not get fainted even if they loss a battle.
Why a player should increase gyms' prestige?
To increase the number of defenders
As the prestige of the gym gets higher, the gym's level, which decides the number of defenders can be put, increases. Increase in the number of defenders means that the gym gets harder to be defeated. To keep the gym longer, gaining prestige and increasing gym level is important.