There is no restriction on foreigners buying property in Germany, no matter whether they live in Germany or elsewhere. You can, therefore, buy property as a non-resident with the expressed purpose of renting it out, or you can choose to rent out your own home if you move away from Germany.