If you leave one there you can not use it whilst it holds the gym. As soon as someone else takes the gym you get the pokemon back with 1hp.
A gym has 6 levels I believe (6 slots) however these slots are only unlocked when you reach certain gym prestige levels. You add prestige exp and rank up a gym by fighting/ training against your own team. Defeat them and you get exp and eventually levels. 1 level = 1 more slot.
To expand on that:
Prestige determines how many pokemon can be slotted in a gym, 2000 per slot.
Increase your gym's prestige by 'training', which means defeating your own gym (defending pokemon heal back to full).
Winning a training session with a Pokemon with CP under that of the defender gives you more Prestige than winning with one with more CP, so exploit type weaknesses.
Battling and winning against an enemy gym reduces their prestige.
You always fight the pokemon in order of weakest to strongest CP.
You can team up with friends to attack multiples on one if you attack the gym at the same time.
Reducing prestige enough to remove a slot means that the weaker pokemon get removed and sent back to their owners with 1hp.
Once you have reduced their prestige to 0, the gym becomes grey and can be claimed. ANYONE nearby from any team can claim it, so be quick after your win.
The number of gyms you have a pokemon at gives you reward every 21 hours (500 stardust and 10 pokecoins).
Hope that helps.