Havana was one of the most important Spanish cities in the New World. What Spain found in Havana was an easily protected harbor and excellent staging area for the return voyage to Spain. Columbus first set eyes on Cuba in 1492. By 1511 Spain had regular settlements with the port town of Havana being established in 1514.
The Spanish Silver fleet would start its collection in Venezuela and Peru, making stops in Panama and along the coast of Mexico. As the ships collected their cargo, they would head for the safe harbour of Havana, where the would form a massive Flota before heading back to Spain. It was hard to keep such an operation a secret and just about every pirate and smuggler in the Caribbean saw the waters around the Cuba as the place to go plundering.
The pirates had little trouble finding out when and where the the silver fleets would be coming from. Many of the Spanish colonists throughout the "Main" and in Havana were more than willing to tell them anything they wanted to know, for a price. You see, the Spanish royal family controlled the "Casa de Contratación" or House of Trade and stipulated that merchants within the colonies could only trade with specific merchant seamen. In other words they told the Spanish colonists that they were not allowed to trade with other towns in the new world or make trade arrangements with any settlements of foreign governments. The colonists had to buy goods that were brought to the colonies from Spain and could only sell goods to the same ships.
Now this arrangement basically meant that if you remained a loyal colonist and obeyed the rules as laid out by the royal family, you would starve to death. Just about every Spanish colonial merchant was willing to sell or trade with any other person living in the New World, but they had to do it carefully for fear of retribution, or they had to pay off local administrators.
As such many Havanans (as well as citizens of other towns) were corrupt would let slip when the silver ships would be arriving. It was a win win situation for the citizens of the towns. If the pirates captured the ship, then the pirates would have money to spend in the New World and the Spanish merchants would have a place to sell their goods. If the pirates failed, then the town people could witness a hanging or two.
As time passed, the town and it's harbor became well fortified, with the forts, Castillo de los Tres Reyes del Mooro and Castillo de San Salvador de la Punta protecting the entrance of the harbor. A fleet of Spanish galleons would also patrol the water in search of pirates. And if this were not enough, every night, large chain that was actually drawn across the mouth of the harbor to prevent saboteurs from entering the harbor and sinking ships. The reefs outside the harbor added to the protection as well as added to the loss of many silver ships.
All of these measures made Havana one of the best fortified cities in the New World. Despite all of these measures, Havana would repeatedly get invaded and on more than one occasion it was sacked by pirates or foreign nations.