Pokemon Keep Popping Out Of Pokeballs

Catching a Pokemon in Pokemon Go only to watch it pop out is one of the most frustrating aspects of the game. So why does it happen and how can you stop it?