Because this is what underlies all of this -- is the premise that Iran is behaving in an unacceptable and illegal fashion and therefore a legal response with violence is justified.
This all presupposes that Iran is breaking the law with their production of nuclear weapons. Are they breaking the law with their production of nuclear weapons?
Was Iran's activities funding militias in Lebanon, Syria, Iraq and Yemen, which launched attacks against Israel and US forces "legal"? Which of the US' activities were "legal"? It's all mostly a bad joke.
However Iran has the stated intention of destroying the state of Israel, and actively incites it's proxies to attack Israel, and this could be seen as a valid justification for taking action. Not a lawyer though.
Is the US funding of Ukrainian militias "legal"?
Not that we would or should but the US could attack any number of countries today and only if one or more countries stopped the US would the victor be able to say it’s illegal.
Geopolitics operates in an explicitly anarchic arena.