I didn't know that! One wonders what the hell they were thinking in the first place.
Giving away missiles that were already there, unknown to the CIA, and not even concerned by the agreement would certainly have been a good move to keep the alliance with Cuba strong - IFF the leader was considered stable enough to consider them as a gift of goodwill to establish long term deterrence, and not something to be used within the next years - or even right now.
The guy must have mastered the art of negotiation to take them away - or to have given much more in return to Cuba that was required to maintain an alliance (ex: exports, money, ...)