I read somewhere that it goes back to the Christian obsession with "pure blood" during the Reconquest of Spain, like proving that there were no Moors or Jews in your family history. Another source said it goes back further, to the Visigoths. Thank you in advance for any responses!
It is a very complex issue, to say the least, as it was more custom than norm until the late XIX and early XX century. In that last time frame it was legislated that people would need to use two surnames, the first from the father and the second from the mother. Prior to that, it was most common to go by using only one surname, although the nobility and bourgeoisie normally styled themselves with two surnames, normally one from the father and one from the mother.
However, this does not give a full picture, as from the XVI century you can find a load of nobles and hidalgos (lowest rank of nobility) using two surnames. Some names may ring a bell: Miguel de Cervantes Saavedra, Francisco de Rojas Zorrilla, Francisco Gómez de Sandoval y Rojas, Ana de la Cerda y Mendoza, Gonzalo Fernández de Oviedo y Valdés, or Antonio de Herrera y Tordesillas. This use of two surnames was to show the connections of your lineage, to demonstrate that you were well connected or related to someone of relevance. This though, was subject to a lot of irregularity, sometimes using the surnames of some grandparents: Miguel de Cervantes was son of Rodrigo de Cervantes and Leonor Fernández de Cortinas, Gonzalo Fernández de Oviedo was son of Juana de Oviedo and a certain someone of the Valdés lineage. If you go further back in time, you will see only one surname being used, even in the cases of really important people like Pedro González de Mendoza, Íñigo López de Mendoza or Gonzalo Fernández de Córdoba.
It is largely on the XVI century when the use of two surnames starts to become a thing, but it has nothing to do with the Statutes of Blood Cleanliness promulgated by Inquisitor Martínez Guijarro. The use of two surnames was mostly limited to the nobility and hidalguía, but some bourgeois families used them too, imitating the nobility's customs, like many families from Burgos' bourgeoisie who were conversos: Salamanca, Cartagena, Lerma, Santa Cruz, and the like. It was not even a secret that they were of Jewish ancestry.
This customs from the metropolis made it to America with the population migration there, and imitating the customs of the nobility, mostly represented by the viceroys.
Sources:
Ryskamp, George (2005), «La transmisión de apellidos en España y las colonias americanas, 1500-1900», in XI Reunión Americana de Genealogía .
De Prado Sagrera, Antonio (2012), «El nacimiento del sistema oficial de doble apellido en España», in Hidalguía, LIX, n. 351.
Bergua Cavero, Jorge (2005), Francisco de Enzinas. Un humanista en la Europa de Carlos V. Madrid: Trotta.
Fernández de Oviedo (1555), Batallas y Quinquagenas. Manuscript in the Real Academia de la Historia. Modern edition by Juan Pérez de Tudela (1983 and 2000, Madrid: Real Academia de la Historia).