The USSR ran away defeated from Afghanistan and never nuked it as a retaliation, same as the USA that ran away from Vietnam defeated and didn't nuked it either after that.
So i believe there's high hope that even if Putin's "special operation" project in Ukraine ends in defeat, he will not go for nuke (as long as none has the silly idea of invading their main land of course).
Totally different situations. Afghanistan was a straight up Soviet colonial war, while Vietnam was a really bizarre attempt to salvage a friendly power from a failed French colonial war. Neither were considered core territory of the respective powers. Not only has Putin declared that Ukraine is Russian soil by right and he is going to put the flag back where it belongs, there's a very good chance this war's going to progress into previously annexed Crimea that Russia's already claiming is their sacred soil. Putin's loss of face from losing this war is orders of magnitude greater than the Soviets or Americans suffered in the wars you mention.
More important, the leadership of both the Vietnam-era US and the Afghanistan-era Soviet Union were far more stable than Putin is. Johnson, Nixon and Ford had to worry about the effects of the war on their elections, but the worst case scenario the US faced was the opposition party getting an edge in votes. There was absolutley no risk of the government collapsing, and the people involved risked no greater fate than early retirement. The Soviets faced worse consequence, but nobody was going to pull Gorbachev down and hang him from the nearest lamppost either. Ultimately it was just one more step on the road to ruin for the Soviets, and nobody really expected it to be that much.
Putin's not quite in the position of a Romanov in late 1916, but he's far closer than the examples you pulled. And removing him from power isn't going to be a quiet "you lost the election, it is time to go" moment - it will be an outright coup, with Putin either "killed in the fighting", or later "shot while attempting to escape". Losing this war might not push him off the cliff, but it will push him a lot closer to the edge, and he knows it.
Of course, the fact that the very first shot the US fires if the balloon goes up is going to be a deep-penetrator right into his lap has to be on his mind as well.
Vietnam was an unpopular war and Americans WANTED to see it over.
That's fairly revisionist. Pop culture likes to pretend that there was massive opposition to Vietnam for the entire war, but in reality the conflict was extremely popular until near the very end. There's documented interviews and polls that suggest even hippies and beatniks were fairly divided about the war, and a hefty proportion of both supported it.