Iran signed the NPT.
The NPT did not exist at the time of the US developing nuclear weapons, and it explicitly allows US (and other pre-existing nuclear powers') weapons.
Israel, like India and Pakistan, simply never signed it, forgoing the international nuclear technology market as a consequence but also avoiding a treaty obligation not to develop them.