Please check directly the website of the US Embassy in Spain or Spanish official websites for Information.
But I don’t think you need a covid test to get from one city to the other.
You need either a test OR proof of recent enough vaccinations. Thats for enter ESpana-the airline may also pose other rules by their own.
Once youre IN ESpana, there are no more checks. Though perhaps the odd place/HTL may pose its own rules. Its also still wearing Masks in all transit
Its often a drag to wade through all these regulations-general mainstream forums like tripadvisor most often have it explained in plain /en/ aimed at ignorant visitors
Although COVID regulations aren't as volatile anymore as they used to be, checking information on sites like reopen.europa.eu is way more reliable (especially if you click through to the national websites) than opinions and past experiences on a forum like this one.