I think I have a hypothesis, but it sort of fits the facts. From what I can gather, the so-called “consulate” at which these Iranian officials worked was not accredited to the national Iraqi government headquartered in Baghdad. Rather, they were there at the invitation of the Kurdish authorities. While the Kurdish authorities operate what is almost a defacto state, and indeed have invited diplomats from their nearby neighbors to come and set up ‘consulates’ neither the US nor Iraq-in-Baghdad nor most of the world recognizes the independence of Kurdistan and thus those governments also do not recognize the validity of any diplomatic credentials or immunities issued by what they see as a mere provincial government.
Thus, from the US point of view, the building in question had no special legal status, regardless of whether it was flying (as reported) an Iranian flag.
As to what motivated the US action, I still have no more idea than I did yesterday, when I worried that this might be a deliberate provocation of Iran in the wake of Bush’s bellicose speech. And I don’t see why the US forces would be willing to act in a way that would doubtlessly anger (and did anger) the local Kurdish authorities.
But I’m starting to think that I understand the US legal position — and that if the facts are as I hypothesize, even to agree with it as regards the non-diplomatic status of the building and its occupants. (None of this of course speaks to whether there was justification for the raid, its motives, or how the persons detained may be being treated.)