Well it's tough **** on them then isn't it while Spain is in the EU. EU trumps the democratic wishes of a country. Spain has been welcoming British ex-pats long before the EU said they had to though.
The government might not be building them but it gives approval for them by way of planning permission (at least in theory anyway).
Why wouldn't they welcome people? Spain is a huge country and there is plenty of sunshine for everyone down there. And tourists (elderly or otherwise) still bring in a lot of business for the cash strapped south.
I'm 100% sure that there are better ways of funding few extra hip replacement surgeries compared to closing ones borders or stopping people from building holiday homes.
Tiny modification to the healthcare funding system, maybe by forging a deal with UK government where UK funds part of the expensive operations would probably solve issues without preventing Brits and Spanish people from getting what they want (retiring in the sun for the former & development to the tourist sector for the later).
Personally I'd even go further and advocate for a EU-wide healthcare balancing system where let's say ~10% every country's healthcare budget goes to EU and then EU divides this money back to countries according to the number of cross-border patients they are servicing. Or something along these lines, I'm sure their bureaucrats can make it a tad more complex system just to ensure that more bureaucrats are needed in next decade as well, but the idea still stands.
If this kind of system would be tuned properly it could even convince people to go "healthcare shopping" to countries where the services are provided most efficiently reducing overall costs and increasing the healthcare outcomes.
People coming from outside of EU are a different thing, though unlike the 60+ retirees, the demographics are much more favourable allowing at least in theory these people to contribute to the local economy by working.
edit: the sentiment that I read from your posts is that Immigration is the newest incarnation of absolute evil and closing the borders is the only sensible thing and that this magical act would solve all issues in UK. I don't quite understand the logical thinking here...