I understand it to an extent with its location and sugar production, but to stretch yourself so thin to keep an island whose inhabitant is literally hacking your men to pieces, is insanity.
They had lost all other colonies, why weaken yourself so much? Maybe its a simple answer and I am missing it. Thanks in advance.
The two biggest reasons were economic and ideological/identity based.
Let's get the more obvious one out of the way first. In the 19th century, sugar promised enormous economic rewards for countries that produced it. Sugar promised rewards so significant that fortunes could be made in less than a generation. The big drawback for sugar production was that the model used was often intensive plantation agriculture, which exhausted the land and burned the local forests (wood was used to feed the fires needed to refine/process sugar from cane juices into crystallized sucrose). Within a few decades, most of the small islands in the Caribbean were exhausted and crop yields had fallen. Barbados was largely exhausted by the late 17th century, for example. This meant that land took a larger effort to produce less crops than those cultivating on virgin or near virgin soils. Cuba has well over half of the total arable land in the Antilles. The early sugar boom consumed the forests and lands around Havana (turning the 'forest of Havana' into the 'plains of Havana'), but even by the late 19th century the large plantations were still penetrating into the center of the island and, with the help of steam powered trains, tons of arable land was still available for easy cultivation. In short, not only was Cuba the source of a product that produced massive windfalls, but it was one where decades of agricultural expansion were still possible.
There's an important caveat here. Sugar was on the decline in the international market, relative to how it was at the end of the 18th and beginning of the 19th centuries. More and more lands around the globe were being used for sugar cultivation, on the one hand, and historic markets for Cuban sugar (the USA, Europe) had important domestic producers, even going so far as to have protectionist policies protecting these producers. The USA had a growing sugar producer in Louisiana and Hawaii had been annexed only recently.
With that said, the Spanish economy had little else going for it. Spain depended on its colonies both for the large rents provided through tariffs on imports and exports as well as serving as dumping grounds for Spanish industrial products (textiles, etc.) which often had difficulty competing in freer markets. Its agriculture was often still pretty backwards compared to the rest of Europe and the country had been ripped apart by numerous civil wars throughout the 19th century (particularly the Carlist Wars). Cuba was the goose that laid the golden eggs.
Now, to the more interesting ideological reason. Being a 'colonial power' was more than just a practical decision. It was part of Spanish identity and pride. Spain was the original colonial power of Europe. It was the first to 'bring Christianity' and 'civilization' to foreign lands. For centuries, its colonial empire remained the largest in the globe. Spreading Catholicism and having a colonial empire was part of the Spanish monarchy's reason for existing. As long as they maintained at least a fraction of that empire, they could hold on to the idea that they were still a 'power' even if they weren't up there with France, Great Britain, or Germany. Domestically, Spain was still deeply divided by regional identities which threatened to break the country apart; a foreign empire gave them a united purpose which they could collectively exploit.
To lose its remaining colonies would have been a huge blow to its collective identity and its economy. The loss of its major remaining colonies (Puerto Rico, Cuba, the Philippines) sparked a period of introspection, as well as a depression, which led to decades of continued instability.
Regarding Cuba's economic value to Spain, Manuel Moreno Fraginals: El ingenio: complejo económico social cubano del azúcar.
On the problems with sugar production in the British Antilles (ie. British West Indies), Eric Williams: Capitalism and Slavery.
Regarding Spain's identity crisis after the loss of its remaining colonies, Raymond Carr: Modern Spain, 1808-1975.
On Spain's long fractured national identity, José Ortega y Gasset: España Invertebrada.