If you could expand on this I would appreciate it. I think International law is gray at best and basically comes down to various treaties and charters. Though not used much since the UN, the US did give an ultimatum to Iran and Iran admitted they were violating UN charters with regards to nuclear proliferation. The attack on military targets associated with nuclear war would seem to be in scope.
I think the big unsolved question is how immediate the threat of Iran using nuclear weapons was, and if those weapons could reach the United States.
There is a nuclear non-proliferation treaty, and Iran is a signatory. A proven breech is supposed to be referred to the UN security council to be dealt with. That never happened, possibly because Iran would not allow proper inspections.
More broadly, every country has a right to defend itself against attack, or the immediate threat of attack. Your defense, though, like all military actions, has to be proportionate to the threat. If there was a court that heard these cases the Iranian lawyer would argue that a) they were not developing nuclear weapons, and b) those weapons were not close to being developed (ie they were a distant threat not an immediate one) and c) that those weapons were not capable of reaching the United States and thus were not a threat to U.S. at all, and d) the U.S. response was disproportionate. An American lawyer would more or less argue the opposite.
The truth is I don't know what the status of Iran's nuclear program was, I don't trust Trump to be honest and I don't trust Iran to be honest either. I do think, on an objective basis that killing the head of state and trying to wipe out their navy, air force, etc is well beyond what is needed to stop any nuclear threat that may have existed.
If you have the time there are some great books out there on the International Law of Armed Combat, some written by respected serving military men (ie practical rather than political) that can give you a good grounding in this stuff. But I warn you it is a rabbit hole that can eat up a lot of your time. It's a fascinating area, and a lot of it was just plain ol' made up to be used at Nuremberg to deal with the left over Nazis, a movement lead by the United States. Some aspects of it go back to the Lieber Code from President Lincoln. The United States deep investment and involvement in the creation of the law of war makes Trump's and the Breck Girl's (my nickname for Hegseth) lack of interest in it particularly unsettling for international observers like me.