Not that often but it does happen, usually in Spain mind. Example, Madrid loaned Casemiro to Porto, they activated the option to buy but Madrid had a buy back option which they then activated, and the rest is history.
It's more of a safety net, to prevent the Cahill scenario from happening again. We sell a player who's not quite good enough at the minute, and if they turn good after a couple of seasons we buy them back, if they are rubbish, we don't.