I don't think Spain had much interest in the Caribbean at all after they pulled all the easy to get gold out of it. Almost all their holdings revolved around shipping gold back to Europe to fund their stuff over there. Just about any time it stopped being profitable or they ran into any resistance, they pulled out. The few holdings they still had there in the 19th and 20th century were just the ones that hadn't bothered rebelling against them yet.
Granted, this is a very simplified view of things. I'm sure it's not that simple. But Spain does have a history of basically "Go in, mine the gold, leave. If some of our people want to stay there and call themselves Spanish, that's all cool, but don't expect much support."
That would be their holdings in the Americas, most of Spanish money (or really, all money) made in the Caribbean during the colonial era of the Caribbean was made through sugar plantations or some spice plantations. Thus while they would've liked to retain them, the decline in value of sugar, end of slavery and the cost of defending the islands from much greater naval powers simply wasn't worth it, and they wouldn't try retaking say, Cuba, knowing the USA would put an end to that very quickly. That and they're more busy with internal and external pressures from jihadis, traffickers and civil unrest that they wouldn't be thinking about a transatlantic annexation of all things
Trump's already beaten the odds in a dozen different ways. I can see him managing to pull the right events to grant Casus belli against the Kingdom of Castile.
Diplomatic insult cb
And then they were surprised when their colonies hated them and wanted to rebel.
There's a lot more to it than that
In the colonies you had a certain class of Creoles (Spanish subjects of European descent born in the colonial provinces of Latin America) whom held most of the political, military and economic jobs, careers, offices and posts of prestige and economic gain, and also benefited from a caste system which enshrined legal privileges, social status and even beneficial taxation versus the rest of the nation. This group was inevitably integral to the running of the Spanish Latin American Empire and integral to its dismantling. These elites were well-educated, and it didn't take long for enlightenment ideals of liberty to spread after radical texts from protestant nations were translated into Spanish, though it's worth noting that the ideals of liberty were carefully selected or discarded and limited largely to the colonial elite. In the 18th century the Spanish Bourbon dynasty would attempt to reform the Spanish Empire, seeking to centralize power under the Crown instead of in the hands of the Creoles. Administrative posts were favourably given to Continental-born Spaniards over the Creoles, the Bourbon monarchy successfully oversaw the switch from much of the economies of Latin America from treasure-fleet plundering to trade, which had the consequence of making the Creoles more economically powerful but politically weak - so inevitably they were hungry for more money but frustrated by their lack of means to do so. Importantly, the Spanish government discouraged and disallowed the Spanish colonials to trade with the European colonies in North America or European nations in Europe, only within the Spanish Empire. The elite status of the Creoles was diminished as the Spanish government deliberately undermined the caste system.
This created a powerful faction, but the faction wasn't agitating for liberty - predisposed to ideas of it, but they still supported remaining within the Spanish Empire. All that changes when Spain allies with the French Monarchy, joining the French in war against the British. This was unfortunately prior to the Royal Navy becoming the foremost naval power in the world, which was somewhat a diplomatic error on the part of Spain, as the Royal Navy subsequently cut off lines of communication between the Spanish Empire and Spain.
Creole traders couldn't actually send any ships to trade with Spain, because the Royal Navy was in the way. Creole traders also legally couldn't trade with any other colonies or entities except Spain. Spanish governors and messengers couldn't travel between Spain and the colonies, and all of this meant that there was a simultaneous breakdown of effective Spanish rule over the colonies, and the Creoles being given permission ("given," in the sense that it could not be refused) the right to trade with anyone. This greatly expanded the political and economic powers of the Creole, and most of all gave them a taste of the benefits of independence and self-government. Things would completely turn fubar when the French turned on the Spanish, and the Spanish were now diplomatically isolated, and to make matters worse the Spanish King and his heir were imprisoned by Napoleon. Given that power was centralized under the monarchy, and the monarchy was now gone - Spain's legitimacy to rule over her own state evaporated overnight. France's efforts to consolidate control over Spain and the Spanish Empire didn't work, caused a civil war, and amidst all this chaos and evaporation the Latin American colonies declared independence & the Portuguese Empire moved its capital to Brazil, which of course set the stage for future Brazilian independence.