The reason certain countries maintain their nuclear capability are historical.
The arms race happened as many countries, but particularly the two major powers of Russia and the US, competed to have a more deadly stockpile, and then the other would up their own capabilities to try and create a balance.
Eventually there were efforts to stop this which involved many countries giving up their weapons, and the ones that kept them reducing numbers significantly. The reasons for who got to keep them were pragmatic to a large extent - neither the US nor Russia, who were the great powers at the time, were going to give everything up, especially wile the other might still have nuclear armaments. But because of the nature of world political alignments, there was a kind of balance between the differernt factions achieved. It was also felt that both the USSR and the US were able to see the bigger picture and would avoid creating a worldwide nuclear crisis.
What no one has wanted however is regimes that seem to lack that kind of self preservation to have nuclear weapons. Ones which cannot safeguard their nuclear stockpiles appropriately, lack the technical ability to safely manage them, or who would potentially launch them without caring about the consequences.
And that's Iran. The beliefs of the regime are around the idea that there is a divine mandate for them to destroy the west, and Jews in particular, and also that their own destruction in doing so is martyrdom.