USA developed nuclear weapon in a race against the Nazis, who were already developing the next generation of weapons, such as jets and missiles. Hitler was not afraid to use the these weapons, which would soon include nukes. He would have nuked London using his missiles. England was the last stronghold in Europe, and then it was off to the USA. Luckily, Hitler did not wait for his advanced weapons before he started his invasion of Europe. Had Hitler waited, the USA may have been beaten to the punch. Hitlers early aggression alerted us to his futuristic weapons plans. Many scientists left Germany, out of fear of his intentions, with their new science. The US and Russian each got some of these scientists.
Thereafter, the international litmus test for nukes was, countries who are aggressive, by their rhetoric and behavior, would not be allowed to have nukes, while defensive countries, usually connected to the allies of WW2, would be allowed.
USA is a super power and only used nukes to end the war with offensive minded Japan. After that it was nothing by R&D. Russia and China also would develop nukes. Both were part of the Allies in WW2, with Russia against Germany and China against Japan. They were both defensive countries, who had been invaded and wanted a future deterrent.
Iran is a sponsor of terror, who openly chant their intention to invade and kill. It is feared they will use nukes as an offensive weapon. Nobody is threatening Iran, since they are strong in that region. Nukes are not needed for their defense. Iraq was a threat but Iraq is no linger aggressive.
Countries, who are dictatorships, like Iran, with poor economies, tend to put all their eggs in the war basket. The same is true of North Korea. There is fear that some renegade generals, are itching to use the nukes, for the glory of war. Whoever nuked Israel, for example, would get their names in the Iranian history books. The temptation is real, therefore, nukes are forbidden.
Saudi Arabia is not aggressive and if they were being threatened with invasion, they may decide on nukes and may even get them. This litmus test allowed Israel to get nukes decades ago.