In short, yes! The Spanish government welcomes and even encourages foreign buyers in general. Though if you are specifically looking to buy a holiday let, you might need some legal help with the bureaucratic part of it.
The buying process for property in Spain for foreigners is relatively simple. First and foremost you’ll need to get an NIE (Número de Identificación de Extranjero) also known as the Foreigner’s Identification Number. This is the Spanish financial number, and you need it, as an expat, to do any fiscal activities in Spain. You can apply for this number yourself, or you can hire someone holding a Spanish power of attorney to get it for you.
Spain has one of the most successful Golden Visa Programs in Europe. This is a residency by investment scheme, which grants the holder residence in Spain in exchange for an investment in real estate. To qualify for the Golden Visa you need to buy a property in Spain that is worth at least €500,000. After that, you can get a residency visa, which can eventually lead to citizenship if you reside in the country legally for at least ten years.