It only works when you currently have a Pokemon in a gym, not if you previously did. If you didn’t claim then, it’s lost. Next time you put one in a gym, try immediately going to the shop screen, then tapping the icon at the top (it looks like a shield). You should get 10 coins and 500 stardust. This is what I always do, and I haven’t had any problems with it.