Officially, medical care in Spain is "free" only to people with EU citizenship or approval. Even if you are not European, you have a right to medical treatment at any of the public health facilities along the way... but how it´s paid-for varies from place to place. Often the people who do these things will take down info. on whatever insurance or plan you have from your home country, and that´s the last you hear of it. Sometimes, especially if the treatment includes X-rays or overnight stays or medicines, you´ll be sent a bill later on, or asked to pay upon leaving.
What´s remarkable is how little you´re asked to pay. Once in Madrid a man traveling with us suffered what appeared to be a heart attack. He was whisked away in an ambulance to the hospital, where they did the full emergency intervention, EKGs, etc. overnight. Thankfully it was just a bad case of indigestion. And the bill? 250 Euro. Amazing.