I've been reading about the Cuban missile crisis recently and this element has so far been completely glossed over. It seems like an absurdly reckless move that would inevitably lead to a crisis (though if you think otherwise I'd be eager to hear your view). Did Krushchev really expect that Kennedy would just sit back and let the USSR stockpile missiles in the US' backyard? Was he just hoping they would go unnoticed? What was the thought process here?
There's a lot to it, but the gambit was that a) the US had put missiles in the USSR's back yard (the Jupiter missiles in Turkey, to say nothing of the over a dozen nuclear deployments that the US ringed the USSR and China with in the late 1950s), and this was both payback and a stimulus to remove them; b) this was also tied up with Khrushchev's feelings on the Berlin crisis, and he thought it would give him leverage there; c) Castro wanted the missiles so that the US would (once again) not try to invade his island, as they had tried to with the Bay of Pigs.
The idea that the US would freak out about this was not obvious. The US leaders themselves acknowledged, privately, that the missiles in Cuba did not in any meaningful way change the balance of military power. The US itself had been engaging in "absurdly reckless" behavior of the same order for several years. The US chose to escalate it to a full crisis; it was not obviously one, and the Kennedy administration could have had many different responses to it than the one they had (which brought them to the brink of war and was only really released because Khrushchev allowed them a way out of it). The Soviets were extremely surprised by the intensity of the US response.
Which is to say: when you look at it from an exclusively American perspective, yes, it looks crazy. But if you look at it from the Soviet perspective, the US reacted in a very dangerous and irrational way to what was, at worst, a tit-for-tat operation.
I would like to add something to the above answer. With the mentioned points I mostly agree with, but I'd like to add directly from Khrushchev's own memoirs as I think these would be quite relevant to this question.
Khrushchev wrote about this in his memoirs. It must be noted he wrote these memoirs in the late 1960's, while in forced retirement - and the Cuban Missile Crisis was cited as the reason for ousting him from power by the Politburo in 1964.
Khrushchev's later remarks are not necessarily what he truly thought at that moment, and he tried to save his legacy, but it does tell us something about his line of reasoning.
His version of events begins with the Cuban Revolution and the fact that for a while, the Soviets did not expect Cuba to turn communist anytime soon. They did have a KGB officer who had coincidentally befriended Castro's brother a few years before and told Moscow that Raul Castro was a Communist. Eventually, Cuba began to receive aid, and started nationalizing US assets, followed by the Pig's Bay invasion in 1961. Unexpectedly, Castro declared his regime Socialist, and according to Khrushchev the Cubans began to form a symbol. If Cuba became a success, more socialist revolutions in Latin America would follow.
At the same time, the USSR and NATO butted heads in Europe over West-Berlin, as the Soviets demanded West-Berlin to become a neutral ground and that NATO would withdraw its troops. However, Khrushchev writes he was fairly confident the West wouldn't start a war from West-Berlin. About Cuba however, he was not so sure. He was convinced that after the failed invasion of 1961, the US would continue to try to overthrow Castro.
What could the USSR do to prevent this? Khrushchev argued that making firm statements and issueing stern warnings would not deter the US if it was not backed up by "real force". In his view this is how "imperialists" are to be treated: they only understand force.
Cuba had to be protected at all costs: if America could crush Cuba, it would undermine the "revolutionary will among many other peoples and nations". Cuba needed to survive as an example for other countries to follow suit. If I may say so, it almost sounds like an inverted Soviet version of the domino theory: if one revolution fails, all will fail.
Then also comes the problem that Soviet missiles at that time could not yet reach US territory from the Soviet Union, and its strategic bombers would have to go on suicide mission to deliver one atomic bomb to the US.
Khrushchev worried deeply about "losing Cuba". He worried about the blow to Marxist-Leninism in the world that would be, he worried about Soviet prestige (Khrushchev's personal ego was deeply connected with Soviet prestige) and he wanted to show the world the USSR could do more against US agression than expressing mere protest at the UN.
The "obvious" solution to Khrushchev for defending Cuba was to do what the US had been doing to the USSR already: placing nuclear weapons. Khrushchev also sounds a bit vengeful, as he wanted to threaten New York and make America "feel threatened" like they had done to the Russians.
According to his memoir, he developed his plans in private while visiting Bulgaria, and continued not to discuss it with anyone, because he knew that if he and Castro would do this, it had to be kept absolutely secret. Eventually when he had decided to do this, he presented the plan to the leaders of the Central Committee and gave them a week to think about it.
"Cuba must become a torch blazing in the night", Khrushchev wrote. "A magnet of attraction for all the oppressed peoples of Latin America fighting against exploitation by the American monopolies".
Khrushchev's Politburo colleagues cautiously supported his decision, but basically told him it was his decision and they would support whatever he decided. He felt the burden of responsibility not to let things escalate into war, but, he tries to argue his strategy was one of agression to preserve peace. If the USSR continued to be "weak", back away, and do concessions to the imperialists, he wrote, then this would inevitably embolden them and lead to war. Khrushchev believed he had to draw a line to protect Cuba, show his teeth to the US, appear threatening, and thereby maintain balance in the Cold War and with it, peace.
He concludes in his memoir that the Cuban Crisis "brilliantly set off our foreign policy" and considered it a "brilliant success without firing a single shot".
I hope this further illuminates some of Khrushchev's thinking during the Crisis. I must warn that this man changed his thoughts and ideas as often as the weather, depending on his mood and temper, and that his memoirs above all reflect his own reconstruction of what he was doing.
Nikita Khrushchev & Sergei Khrushchev (ed.), "Memoirs of Nikita Khrushchev Volume 3: Statesman (1953-1964)"