The base is not some favor to Spain. Who does Spain even need defending from? It is a means of regional power projection for the US, granted to them for free as a favor. They've been very ungracious guests lately.
"Granted to them for free"? The US has been paying Spain for base access since 1953. Hundreds of millions per renewal cycle in military aid, economic assistance, and direct spending. It was never free and it was never a favor. Spain negotiated compensation every time.
"Who does Spain need defending from?" Nobody, because of the security architecture my tax dollars built. That's not evidence the bases are a favor to us. That's evidence they worked. You're welcome. And if they can't be used when it matters, I won't lose any sleep if they get closed.
No, specifically, which of their neighbors do they need protecting from.
France? Portugal? Andorra??
The bases are a remnant of American imperialism, they serve no purpose but to further American interest. Any pretension they do anything else can only be explained as late imperial delusion of grandeur.
The fact the Spanish don't let you use them to engage in your unforced act of historic self harm can be seen as yet another favor.
Spain had the largest empire in the Western Hemisphere. Extracted silver, enslaved entire populations, and lost it when we kicked their teeth in during 1898. That's imperialism. Paying someone hundreds of millions to let you park planes on their runway is not. And "which neighbor do they need defending from" is a question that tells on itself. If you still think wars are about neighboring countries you haven't been paying attention to anything happening in the world right now.