MANDATORY: Passengers arriving in Spain from countries that DO NOT belong to the European Union or are NOT considered Schengen associated countries must complete the form, if they do not have a CCD-EU or EU Equivalent.
THEY ARE EXEMPT: Children under 12 years of age and people in international transit DO NOT have to present any certificate or SpTH QR.
You can see all the information here: https://www.spth.gob.es/faq?tab=1