If you are travelling on ONE ticket you will be treated as a passenger in transit and will not have to pass through immigration, or health screening and will remain airside. If you are on TWO separate tickets you will need to pass through immigration and health screening before checking in and clearing security.
The issue here is that you are technically entering Spain, and going landslide, irrespective of how long you will be there. From the perspective of the authorities, for all they know, you could decide not to take the second flight and head into central Madrid instead! Indeed, many passengers on separate tickets, with time on their hands, actually do head into central Madrid for a few hours. I appreciate that is not your intention, but it is a scenario that could happen, and as such, poses an element of risk.
I have flown in and out of T4 during the pandemic, and can confirm that all passengers are stopped after passing immigration, on the approach to baggage reclaim/exit area, by staff undertaking temperature/visual checks, and are asked to show a QR form. After 23 November I assume that they will also ask to see proof of negative PCR at this point. Passengers arriving without a negative PCR from 23 November will be subject to a PCR test and fines of up to €6000. I believe that airlines have also been asked to check that passengers heading to Spain from high risk countries are in possession of proof of a negative PCR prior to boarding.
As previously suggested, you should try speaking with your airline to see if there is anything they can do to help, or what advice they can give.
Edited: 3 years ago