While foreigners can get mortgages, banks often require a larger deposit from non-residents (typically 20% or more ). Estimated Closing Costs
Owning property does not grant you a visa, residency, or any immigration benefits.
Does buying property in Germany give me residency or a visa?