After the botched invasion, Castro went to his Soviet masters and said "See! I told you the United States was trying to take me out by force! I demand you give me nuclear missiles to deter any future aggression by these imperialist dogs!"
And the Russians did. That is how and why Soviet missiles ended up in Cuba. It was a response to the botched invasion with Castro demanding they put missiles in Cuba to keep America from invading him again.
Kennedy also did not back the Russians down. That is the lying news media failing to tell the whole story.
He agreed to remove our missile bases in Greece and Turkey in exchange for the Russians moving their missiles out of Cuba. This was done quietly and behind the scenes so that Kennedy could crow about backing the Russians down, but he actually traded our Missile bases for theirs.
And of course the news liars made him into the "hero" for making it appear that he backed the Russians down.
Wasn’t that also what led to Khruschchev’s undoing as Soviet premier?
The Soviets backed Castro to the hilt because of his strategic importance, but privately considered him a major PITA for his constantly stirring up trouble on the world stage.