Missing the forest for the trees, are you? Wars of aggression are against UN rules, and US is in the wrong regardless of what it hit.
Feels like we're talking here about whether rapist should have known that the rapee was a child or an adult, and they had a good reason to believe it was an adult person (there was mother of the girl standing next to it, so, hard to distinguish...), so yeah, obviously a tragedy they raped a child instead, but it happens sometimes when you rape a lot of people at once. A tragedy, but let's get on with raping more...
Iran has been waging war since the Islamic Revolution and the US claims that there was a threat of attack on US bases and US interests and therefore the attack was in self defense. The body that decides is the UNSC and given the US has veto powers it's not going to obviously declare the US attack illegal.
From Israel's perspective there's an even stronger self defense argument given the amount of missiles aimed at Israel from Iran and the enrichment of nuclear material to military grades while constantly threatening the elimination of Israel. So the US argument that they knew Israel was planning the attack and they knew Iran would retaliate against US interests seems at least on the surface to bad valid.