How do I collect my Defender Bonus?

How do I collect my Defender Bonus?

I put a pokemon in a gym and the gym later on got defeated and replace with another colour. I didn't get any defender bonus from the gym. This happen two times so far.