Buying Pokemon Coins with real money is the most obvious way to get them, but there is another way around it. A post by SlashGear discussed something about this, If you well check your Pokemon Go app, on the upper right corner of the user's display there you can see the shield. The Shield usually has a number in it depending on the number of Pokemons which the player has on a Pokemon Gym, usually it is a number 1 or higher. You need to wait for 21 hours before you can tap the shield and receive 10 Pokecoins each Pokemon on the Gym, it also a bonus that you will be receiving 500 Stardust too. 

However, according to Gamerant, Players should expect some sort of "resistant", because there will also be a lot of teams or players who would try to take over a Pokemon Gym and acquire the coins inside the Pokemon game, this is due to the fact that Pokemon Go has been and is continuously being popular around the globe. 

You also need to consider the fact that according to Cnet, only 10 Pokemons can be assigned per gym, this information is from Niantic itself, the maker of the game; so there is also a huge probability that you won't be able to place a Pokemon on a gym regardless on how much you battle.So the next thing to do is to head on to the next gym and take over it, once done you can assign a Pokemon to guard it. But be quick! because once a gym becomes neutral, other players will try to place their Pokemon on that gym and you will be needing to battle them again before you can take over the gym and acquire free Pokemon Coins.