It's certainly not mandatory across the EU. The rules for France, where your friend was unable to obtain a refund, are described on service-public.fr:
La vente en détaxe est une exonération de la taxe sur la valeur ajoutée (TVA) sur le prix de biens achetés par des personnes de passage en France, soumise à conditions. Le commerçant est libre d'appliquer la détaxe, qui est facultative. L'acheteur ne peut pas l'exiger du vendeur.
Rough translation:
Tax-free sale is an exemption from VAT for goods bought by temporary visitors to France, subject to conditions. The seller is free to apply this exemption, which is optional. The buyer cannot demand it from the seller.
So Apple or any other company is perfectly entitled not to partake in the system if they don't want to. On the other hand, the bit about “only selling to residents” is presumably Apple policy, I don't see what could prevent them from doing it if they so wished.
Liam, Nigel and Tor-Einar have mentioned similar systems in Germany and the UK (+1) and I would speculate that it's the same everywhere in the EU as refund systems are somewhat complex and making them mandatory would place a big burden on small retail operations.