They were well within their right to shoot at the Americans, who were only in the area to provide aid for Saddam, who was gassing Kurds and threatening to gas Tehran. Expecting the Iranians not so shoot back was foolish, and shooting down that airliner in retaliation was plainly barbaric.
The aftermath of the incident has no bearing on whether the Iranian reaction to the intrusion was rational or justified. The order of events does not support such a line of reasoning. What you are basically saying is that nobody should ever shoot at Americans no matter where they are or what they are doing, no matter the current military or political circumstance. Ridiculous.