To piggyback off Monarch: once you ARE able to put a pokemon in the gym, immediately go to the “shop” section of the menu to collect 10 pokecoins (upper right corner). I don’t think you can collect the coins if your gym is taken over before you go to the shop.