This is a fairly complicated question with many different factors coming into play. Primarily, the situation that Spain and Britain found themselves in when their formal empires collapsed were significantly different. Britain's empire dissolved gradually with self-government being granted to its dominions through the latter half of the 19th and early 20th centuries. When it's other colonial possessions gained independence following WWII, some chose to unite in the Commonwealth with these older dominions.
Spain, on the other hand, lost much of its empire in during the Napoleonic wars after Spain itself was invaded by France and it's king, Ferdinand VII, was replaced by Napoleon's brother, Joseph Bonaparte. This action was despised both in Spain and in its colonies. As a result, we see Spain's Latin American colonies attempt in to break away and a domestic rebellion grow in Spain itself. During the war in Europe the colonies were able to gain de-facto independence while the opposition groups inside Spain were able to create a new Constitution which drastically reduced the powers of the monarchy.
Following the Napoleon's defeat and the Congress of Vienna in 1815, reactionaries in Europe were largely able to undo the gains made inside Spain and reinstate Ferdinand VII as an absolute monarch. In Latin America, however, these reactionary forces were much less successful. This is Not because they didn't want to return Spain colonial possessions, but rather the British (and to a lesser extent the US) wouldn't let them. By the 1820s the British were already the largest economic nation in the world, and pursued a dramatically Liberal foreign policy. Both of these facts meant that they would not accept the recolonization of Latin America by the Spanish. In 1826 George Canning, then foreign minister, articulated the "Canning Doctrine" where he pledged that Britain would stop this from ever happening.
EDIT: Spelling