I have always wondered how come the american colonies united as one large state after driving the British out of their territory while the spanish colonies in South America never integrated themselves in a similar manner into a large state even though they had just finished winning a well coordinated, long and bloody transcontinental war campaign against the Spanish Empire in which they won their independence. Not to mention the incredible official cultural homogeneity of the Empire (which ran from the northern US to the south of Chile) in which they all spoke spanish as lingua franca, they had the same currency, same state religion, same laws and similar mores.
One would logically think, as in the case of the 13 colonies, that the newly freed spanish colonies would also unite to form one country but obviously this did not happened. Why though?
Was it the greed of the regional elite creole classes? The extraordinary size and fragmented geographical nature of the Empire?
Or was the well established and mechanical imperial structure of power and governance in which Spanish America was divided into four Viceroyalties and not colonies (and inherited by the newly freed spanish americans ) with the same rights as any other province of continental Spain, the very same reason why the nodes of political power remained separate even after Independence?
World history would have been much different if instead of about 20 separate similar states, they had become one large continental power. Why did they not unite?
There's three big factors that should be looked at. One is the level of interconnectedness between the English colonies v. the level of interconnectedness between the Spanish colonies; one is the nature of the economies of the respective colonies; one is the geography of the English colonies v. the Spanish colonies.
Interconnectedness and print capitalism: I'm going to borrow from Benedict Anderson's Imagined Communities here. He argues that nationalism is essentially a feeling of belonging to a national community that was made possible by disseminating print media (via the advent of print capitalism) in a specific vernacular. This means that a key factor in French nationalism, for example, was the ability of people in France (as a geographical and political unit) to consume print media en masse in French. Another example he points to is Indonesian nationalism which was made possible by a) the creation of the Indonesian language and b) the dissemination of literature in that language. Anderson writes about nationalism in Latin America in his first chapter and I'll borrow from him below.
If we examine the dissemination of print media in the English colonies versus the Spanish colonies we're going to find two prominent trends. One, print media in general was more common earlier in the English colonies than in the Spanish colonies. The English were less restrictive regarding the press than the Spanish, and in general the English were more interested in facilitating capitalism (and by extension print capitalism) than the Spanish. While the English colonies were certainly tied to various forms of "extractivism" ranging from fur trapping to the essentially feudal slave economy in the South, there was a stronger capitalist class in the English colonies than in the Spanish ones. This means that, generally, the structural conditions for print capitalism, and thus the dissemination of nationalist literature in English to would-be-Americans, were more favorable earlier on than in the Spanish colonies.
In the Spanish colonies there was a greater emphasis on resource extraction, and less of a capitalist influence than in the English colonies. This effected (negatively) the dissemination of nationalist literature in Spanish to would-be-"Gran Colombianos" (we'll use that as the placeholder, since Bolivar's Gran Colombia was the most significant political project toward Spanish American unification). What's more, and what's more important, is that communication between the Spanish colonies was prohibited in a way that communication between the English colonies was not. Spain did a better job of centralizing colonialism through Madrid than the English did through London. Communication, and thus the dissemination of nationalist literature in Spanish to would-be-Gran Colombianos, was more limited in the Spanish colonies than in the American colonies. This made it easier for the would-be-Americans to express their nationalist ideas to other would-be-Americans than it was for would-be-Gran Colombianos to other would-be-Gran Colombianos.
TL;DR The Americans had a stronger print capitalism that facilitated print media in a way the would-be-Gran Colombianos did not, and communication between the American colonies was permissible and occurred in a way that was not possible in the Spanish colonies. It was easier for Americans to communicate with a grand national community of Americans than it was for would-be-Gran Colombianos to communicate with a grand national community of Gran Colombianos.
Nature of the economies: In the English colonies there was a strong class of petty farmers that were eager to acquire new land to farm. What's more, there was a capitalist class that was eager for Westward expansion as a way of creating new markets and generating greater wealth. The farmers needed land, the capitalists needed them to get that land. This created a strong emphasis on expansionism in American nationalism. As the colonists found out, the English colonial authorities had no desire to permit this expansion (as they blocked expansion west of the Appalachians) and the west was already claimed by the French and Spanish, and also occupied by the Natives. The need for expansion largely drove the centralization of political authority in the Federal government, as the colonies and then states realized that their need for expansion would best be served by a central authority. This brought together the colonies (and later the states) and united them in a common political project, and strengthened American nationalism.
This was not the case in the Spanish colonies. The economy was based mostly on mineral extraction and sugar production. Unlike the English colonies, there was really nowhere left to expand, and the resources useful to the Spanish American landed aristocracy were essentially already under use or already claimed by other criollos. This meant that even if externally a union may have offered greater strength against outside powers, materially there was very little to promote a union (unlike the farmer-capitalist alliance in the English colonies and early United States). The landed aristocrats throughout Spanish America were inherently more interested in defending their land than the farmers and capitalists in North America were in uniting to acquire more land and markets.
In the English colonies and early United States the landed aristocracy in the South was always the most hostile to independence and later to unification and centralization under the Constitution. Basically, all of the Spanish Americas were ruled by a landed aristocracy like that in the American South.
TL;DR The essentially feudal economy in the Spanish colonies, combined with the lack of area to expand to, did not generate the same material interests toward union that there was in the English colonies and the early United States. There, farmers and the capitalist class had very strong material interests in union, as it was able to provide greater access to land and markets. In short, the American farmers and capitalists had plenty to gain from union, while the Spanish American landed aristocracy had plenty to lose from union and centralization.
Geography: This relates to the issue of interconnectedness. While communication and transport in the English colonies and the early United States was by no means easy, it was far more difficult in the Spanish colonies. Already inter-colony communication was forbidden, and it was much more difficult to get from, say, Caracas to Lima than it was to get from Boston to Savannah. Administration and troop movements were easier for the Americans than it was for the Gran Colombianos, and as such it was easier for the Americans to avoid fracturing than it was for the Gran Colombianos. The geographical disparities also inhibited the spread of nationalist print media, and as such it was more difficult for would-be-Gran Colombianos to hear about and get behind the idea of a union of the Spanish colonies than it was for the would-be-Americans to hear about and get behind the idea of a United States of America.
TL;DR:
The English colonies were more connected commercially and culturally, meaning that print capitalism, print media, and nationalist literature were far more prevalent and stronger than they were in the Spanish colonies.
There was a strong alignment of material interests toward unification in the English colonies/early United States brought on by expansionism. Even if there was a political interest toward unification in the Spanish colonies, there was little materially to push the landed aristocracy toward unification. In fact they were hostile to creating a centralizing government, due to their position as landowners who had nothing to gain through expansion.
Geographically it was easier for the English colonists/early Americans to communicate with one another and conceive of an "America". It was also easier to administrate and defend militarily than in the Spanish colonies, where troop movements and administration were significantly hindered by South American geography.
I can speak at least for Central America.
Native populations, especially in Mexico, were more populous, highly concentrated, and politically organized than those in North America. Without a variety of extenuating factors (notably the bitterness spread throughout the Nahua peoples against the hegemony of the Triple Alliance), they might have even stayed off European colonization for a couple hundred years. The question of native diversity isn't as much of an issue here, as North American native populations were also diverse, but rather the significance that the native peoples' political structure and culture played in the formation of the Spanish colonies. In Central America, the prominence of the Nahua/Toltec/Mayan ruling class led to intermarriage (or, at least, the keeping of mistresses that led to procreation) with Spanish conquistadores, which contributed to more regional identification and political structuring.
Additionally, the means and methods of colonization were vastly different. Conquistadores were perhaps more politically motivated than (at least the initial) British settlers. They immediately established and set up local governments backed by the power and influence of the Catholic church. The regional governments were empirically-minded, always attempting to gain additional territories and resources immediately after conquest.
In this sense, a lot of the amalgamation occurred pre-independence. Semantically, you might have contradicted your own question. Mexico, specifically, was split up into different "states," usually determined or influenced by the regional native populations preceding conquest. During the Mexican revolution, these somewhat disparate "states" fought for independence together and even established another empire in the wake of their victory! It was never really a question, even in the establishment of a republic, that these states would not form a unified Mexico, even in an atmosphere where the definition and identity of a "unified Mexico" was unclear. Mexico even claimed, of course, decently sized territories both in the north (California, Arizona, New Mexico, Texas) and the south (Guatemala). If Mexico had won its various battles for these territories (ironically, if they were more unified), the size of its republic would be much closer to the U.S.
Despite all of this, I might have even been burying the lede here. A lot of these things just fall to geography, resources, warfare, etc. Guatemala, Honduras, El Salvador, and Nicaragua, and Costa Rica did "unite" as a Federal Republic after their collective fight for independence against Spain. It was civil war shortly thereafter that split them up for good. After gaining independence, the British invaded and claimed Belize, which remained a colony until the 20th century. In an a different political climate, they might have formed another large country in the region.
I'm much less knowledgeable regarding South America, but on that continent you have even more geographical, political, and cultural factors, including that fact that not all South American territories were Spanish-ruled. It would have been quite an empire (as it would be hard to imagine a republic thriving over such a large area) if the countries of South America united to form a single entity of any kind.
In sum, this question could obviously be answered in a much larger work, as the development of Central and South American statehood post-colonization compared to what developed in North America is a fascinating issue that has real-world implications today. But the issue of statehood formation is much more nuanced and complicated than whether different regional people groups wish to form a unified state or not; usually it's much more dependent on economic and political power structures that determine governmental polity and state lines.
Because after gaining independence, most former Spanish subjects didn't have the rights that former British subjects did, and the only way they were going to get those rights was through increasing local autonomy.
Unlike the British colonial administration, the Spanish colonial administration governed through a system that would later by termed a "corporate state", where the Spanish governor balanced the interests of haciendados (landlords), the Church, and resguardos/native reservations to create a somewhat harmonious order. This system left out artisans, peasants, and slaves. After liberating their countries, revolutionaries in each country split into two factions. "Conservatives" believed that economic development was only possible through a central government and a unified military, which enforced property rights and a code of law. "Liberals", meanwhile, rightly pointed out that the old colonial system left most of the population disenfranchised, and argued that only local democratic movements could reform laws in the provinces, thereby affecting social change - as long as the central government didn't get in the way.
Critically, both factions were made up of ex-revolutionaries (with Simon Bolivar himself being on the "conservative" side), and both, contra popular misconceptions about their labels, desired some degree of social change. The conservatives wanted to create a modern bureaucratic state with the rule of law, while the liberals wanted to expand suffrage, rights, and democratic institutions on a provincial level. This central conflict was the reason for the "fragmentary" politics of the various large unions that originally emerged after the independence wars, including the First Mexican Empire, Gran Colombia, Peru-Bolivia, and the Argentine Confederation (of which only the fourth survived).
The parties weren't able to find common ground because they were supported by different interest groups. The Conservatives generally drew support from indigenous people (who were fearful of settlers encroaching on their resguardos), haciendados, and the Church. The liberals, meanwhile, drew their support from tenants, artisans, and slaves, who formed societies for democratic reform. One of the main points of contention in most countries was land enclosure - after independence, Conservatives largely took control of every country's cabinet, and passed laws that formalized property rights, which had been looser under the Spanish "corporate state". This meant that the ejidos - communal lands - were rapidly claimed by local haciendados, impoverishing much of the countryside.
The collapse of Peru-Bolivia, Gran Colombia, and the First Mexican Empire all followed a familiar pattern. A strongman rose to power, largely with Conservative support (Iturbide in Mexico, Santa Cruz in Bolivia-Peru, and Bolivar in Gran Colombia), attempted to impose a centralist constitution, faced a revolt from autonomists, and was thus ousted, with the victors partitioning the country between them. This pattern generally repeated in the "rump states" left over from the dissolutions of the grand unions, but the end result was more often increased autonomy in all provinces instead of outright dissolution. For example, the revolt of the liberal Tomas Mosquera against Conservative President Mariano Ospina Rodriguez of the Grenadine Confederation (formerly Republic of New Grenada, modern day Colombia) led to the defeat of the Conservatives, but the only real outcome was the creation of the modern day United States of Colombia, with more autonomy for the provinces.
Other times, the conservatives were victorious in the successor states, which led to brief moments of consolidation, before another civil war or political shift would restart autonomist momentum. Examples of this happening were Antonio Lopez de Santa Anna's victories against rebellious provinces during his first presidency (shortly before his defeat and capture in Texas), and then-Conservative President Mosquera's victory against Jose Maria Obando (also the key actor in the 1830-31 liberal revolt against Bolivar and his ally Urdaneta) in the Colombian "War of the Supremes". As you can see, side-switching among major military and political leaders was quite common. Santa Anna was ironically the main "liberal" leader who deposed Iturbide in 1822-23, while Mosquera led a liberal rebellion against Ospina in 1860-61.
The nature of the autonomist struggle in former Spanish colonies meant that, among the early trans-national unions in Latin America, only the Argentine Confederation survived.
Autonomism in former Spanish colonies was much stronger and more widespread than it was in the United States, due to the aforementioned disenfranchisement of the majority of the population during the colonial period. In the British 13 colonies, subjects were generally free to govern themselves through pseudo-democratic institutions. While the British did show favor to certain families (most notoriously, the Hutchinsons of Massachusetts), in general the colonial governments were sensitive to these local assemblies, which were an accepted part of colonial administration.
In contrast, the Spanish colonial administrations only represented powerful "corporate groups" such as the haciendados, Church, and resguardos. The generals who liberated their countries generally came from the haciendado class, and early revolutionary administrations essentially imposed a more oppressive version of the same system, still empowering those corporate groups while dissolving the ejidos, cloaked in enlightenment concepts like rule of law and strong property rights. In this environment, the only way commoners in former Spanish America could obtain the same rights that colonists in the 13 colonies largely already had was by keeping the central government out of provincial affairs.
Because of this, independence movements in former British colonies were limited to local, and often temporal, interests. For example, the 1812 Hartford treason of New England merchants was over a war that was destroying trade profits. The American Civil War was over slavery, and only had popular support in parts of the American South. Independence and autonomist movements in former Spanish colonies were pervasive and widespread, and at times took hold in almost every province outside the capital in each of the major unions. The unions collapsed because their early "revolutionary" governments were fundamentally repressive and shut out the majority of the population. In order to gain rights, democratic reformers had to go against the central government, leading to autonomism being the central political issue in almost every Latin American country after independence.
Sources:
Fowler, Will. Mexico in the Age of Proposals.
Fowler, Will. Independent Mexico: The Pronunciamiento in the Age of Santa Anna, 1821–1858.
Acemoglu and Robinson. Why Nations Fail.
Aguas, Sergio. Indian Resguardos, Cattle Ranching and Social Conflict in Old Bolívar, 1850-1875.
Grafe and Irigoin. A Stakeholder Empire: The Political Economy of Spanish Imperial Rule In America.
Valdes, Jose. The Imperial Crisis of the Spanish Monarchy.
Rodriguez, Francisco. The Political Economy of Latin American Economic Growth.
Wegen, Pim. The Origins of Post-Independence Political Instability and Violence in Colombia and Venezuela.
Kuchar, Pavel. Liberalism in Mexican Economic Thought, Past and Present.
There's a section of the FAQ devoted to this which you may find interesting.
Others have stated a lot of great reasons why the colonies of Spanish America did not unite. As it was mentioned, the territories of the New World were largely considered proprietary fiefdoms of the Kingdom of Castilla y León, not Aragón. The vast majority of European settlers were of Castilian origin. It is a bit of a reductionist argument to state that they were simply "four viceroyalties". In reality, these viceroyalties were divided into kingdoms, audiencias, and other forms of administrative bureaucracy (such as Captaincies General) that were loyal to Madrid. For example, you could state the Viceroyalty of New Spain consisted of 9 "colonies" at its peak.
Another reason, as stated by others, was that Spain created an infrastructure in which contact with Spain was placed over that of other colonies, but that is not to state that contact between colonies did not take place. The Viceroyalties of Nueva Granada and Peru were in consistent contact in the period following the establishment of the former (1717) in order to facilitate territorial transfer and administrative efficiency, primarily concerning the territories of modern day Ecuador (the Real Audiencia de Quito).
However, it is this point which I have not seen addressed:
Not to mention the incredible official cultural homogeneity of the Empire (which ran from the northern US to the south of Chile) in which they all spoke spanish as lingua franca, they had the same currency, same state religion, same laws and similar mores.
and which I will address here as well.
Although there was a degree of cultural homogeneity, especially amongst the peninsulares who emigrated from Spain and first-generation criollos (Spaniards born in the colonies), it is a misnomer to state that the colonies of the Spanish New World would have shared everything in common, beyond being ruled by Spain, speaking the Castilian language, and having the Catholic Church as its religious body as to be considered as united as the English colonies. Each territory that was ruled by Spain was the product of a different process of adaptive colonisation, and that showed significantly in terms of its population and how the colonists would have adapted to the environments in which they found themselves. Those on the frontiers certainly lived a different sort of life than those in the metropolises of the realm!
Take Mexico for example - the Viceroyalty of New Spain was founded on top of a society which had already been extant for several centuries, and constructing their infrastructure on that of a conquered empire was a process that facilitated Spanish settlement in the area (as opposed to areas in which the Spanish had to construct their societies from the ground-up, such as the Pampas in Argentina). It also was the first colony in which mestizaje (from which the concept of the Mestizo [Spanish & indigenous American/African/Asian] comes from) would have taken place - indeed, they were designated as a separate racial identity from European whites as early as the 1540s, two decades after Spain's conquest of the Aztec Empire. The process of mestizaje is one which took place in nearly all of Spain's colonies, but Mexico is the one in which it is best documented, followed by (to my recollection) Peru. These two nations contained the most prolific of the pre-Columbian empires and thus contained the largest populations by which European Spaniards and Native Americans could mix. The sistema de castas were the legal designations surrounding admixture of races, and they became an interesting art genre in 18th century Mexico - part historical document, part ethnography, part demographic information.
Admixture of races in the Caribbean would take a different route entirely. The taíno (the indigenous inhabitants of Puerto Rico, Hispaniola, Cuba, and the territories of Colombia and Venezuela bordering the Caribbean) would be nearly extinct by the middle of the 16th century, which resulted in an uptick of enslaved Africans brought to the Caribbean to work, and thus resulting in a greater percentage Afro-Latino populations. There were also Africans brought in small numbers to Peru, Mexico, and even as far south as the Río de la Plata, although only in the former do we have documented cases and evidence of even remaining admixture - Peru having a greater number than Mexico percentage wise.
Although these groups all similarly assimilated to the society of their conquerors, becoming Catholic, speaking Spanish, and owing fealty to the Crown of Castille, you would be hard pressed to find an inhabitant of New Spain considering himself the same as one in Peru, Nueva Granada, or Río de la Plata. The cultural influences due to the society in which he was raised would have impacted him greatly, as would his education and personal upbringing, and his views on the territory in which he lived. After being surrounded by Nahuatl speakers for his entire life (or at least being aware of significant numbers of them), a novohispano may consider a Quechua speaker to be as alien to him as someone from the Arab World or East Asia. He would recognise an inhabitant of Lima as a citizen of Spain, as he was, but consider him to be different enough as to have been from another kingdom entirely, much as a Castilian might have looked upon a Catalan in the same time period.
Essentially, whilst there were aspects of the culture of the Spanish colonies which were no doubt shared, each colony or viceroyalty had differing cultural, ethnic, political, and social considerations to take into account, all of which would have prevented, or at least hindered, any sort of federation on shared hispanidad (Spanishness). The closest accounts we have historically are Simón Bolívar's attempted Gran Colombia (in reality just called República de Colombia), the Peru-Bolivian Confederation, and the Federal Republic of Central America. It is worth noting that the nations in question which formed these unions often had shared cultural and geographical ties and were united under Spanish colonial rule, facilitating their unification (if even for a short while - the Central American experiment was tried four more times, the most recent being in the 1920s). You would be hard pressed today to find an Argentine who would support an outright political union with Mexico, and likely even less in the 1810's during the era of independence, the differences which existed were disparate and apparent.
Sources
Carrera, M. M. (2012). Imagining Identity in New Spain: Race, Lineage, and the Colonial Body in Portraiture and Casta Paintings. Austin, TX: University of Texas Press.
Kamen, H. (2004). Empire: How Spain Became a World Power, 1492-1763. New York, NY: Perennial.
Katzew, I. (2004). Casta painting: images of race in eighteenth-century Mexico. New Haven, CT: Yale University Press.
Restall, M., & Lane, K. (2018). Latin America in colonial times. Cambridge: Cambridge University Press.
During the time of colonisation of Spanish America, Spanish Habsburgs kept separated the crown of Castile from the crown of Aragon, so the court of each kingdom managed their own affairs, sort of like a federal kingdom. Under this setting, new kingdoms were created in Spanish America in the name of the crown of Castile. That's why most of Spanish colonisers were from Castilian origin and not Aragon.
That's why all the viceroyalties and kingdoms created in Spanish America were left to handle their own affairs answering to the Viceroy that represented the king in his absence. It was until the Bourbons reforms in the 17th century, that Spanish American started to become centralised handled directly from Madrid, affecting the local creole populace. They could no longer hold positions of power as everyone was sent from Madrid.
During this period, Napoleon invaded Spain, removed the king and indirectly kick-started the wars of independence in Spanish America.
In the case of the Viceroyalty of New Spain, they decided to become independent were news arrived from Spain that the liberals were forcing the king to enforce the Cadiz Constitution which would have turned the Spanish Empire into a liberal monarchy. Powerful local clergymen and landowners of Spanish origin conspired to start a new Mexican kingdom to keep the same structure as before offering the crown to the king or one of his offspring which he rejected. Thus, mostly all of the Viceroyalty of New Spain (several kingdoms and lands like Californias, the new kingdom of Leon, Yucatan, Central America) became the Mexican Empire. Only Cuba and Phillipines didn't join. Central America broke off once the Mexican Empire was dissolved to become the Mexican Republic, and lastly, the US of A basically stole half of Mexico's land in the Mexican-American war in the 1840s.
There are two main reasons for this: geography and culture.
Geographically speaking it is impossible to govern a territory that big, which was one of the reasons why the Spanish Empire divided the territory in the viceroyalties. Also, some countries (though they do not like to admit it) were artificially created to serve as backstop territories in order to stop the advances of other colonial powers (such was the case with Uruguay/Paraguay and Brazil). A proof of this difficulty is that, After the independence, there was an attempt in the northern part of South America to create a big state called the Gran Colombia. However, that quickly failed due to administrative, political and economic issues which were the result of the massive span of the country (though admittedly, there was a lot of rivalry between the Veneluezan and Colombian sides). Another example of this was western part of the US almost up to Canada. The Mexican state did not had the manpower to properly manage/defend these territories which eventually contributed to them being lost to the US.
The economic factor also influenced a lot the geographical division of the continent as different territories had different needs which were mandated by their unique geography and that would not be able to be satisfied under a big overarching nation. Case and point is Panama. They had their own particular economic needs which were the result of their location and their historical way of commerce. However, when they were part of Colombia, said needs were not satisfied as Panamanian politicians were effectively a minority within the Colombian congress and most of the decisions made regarding the peninsula, were made by people who had never set foot in Panama (which is why they had been trying to get their independence from Colombia since mid 1800's).
As for the cultural factor, most territories had followed the blueprint of the traditional cultural/administrative borders that existed before the arrival of the Spanish Empire which would have made it difficult to create a overarching nation in the continent. Added to this, the arrival of the Spanish brought changes in the local culture that varied depending on the territory as the Spanish culture and idiosyncrasy merged with the local cultures in very different ways and led to the creation of very different practices. This was also true regarding the language as Spanish sort of assimilated parts of the traditional languages of a territory, thus creating massive differences between the Spanish dialect (see for example the differences between the Mexican and the Peruvian cultures or the language differences between Chile and Nicaragua)
All of this would have made it increasingly difficult to create a state which would have properly respected each individual cultural/language manifestation. Finally, the issue of culture also influenced their feeling as a nation and most territories would have seriously objected being ruled by people which were not from that territory (take what happened in Yugoslavia as an example). Again, this was seen in the Gran Colombia experiment, when both Venezuelans and Ecuatorians objected -and even resented- that the rule of the country was made from Bogota and that people from outside their territory had a say in how their territories were ruled.