It sure was an own goal by Iran from the funeral deaths, to the lack of Americans killed in the missile strike to downing an airliner full of their own people. It is entirely possible that this airliner may have prevented further escalation and has made everyone rethink going forward.
I don’t think I’ll ever understand the missile launch, if anything the US would have responded with cruise missiles, I can’t imagine them sending in planes at 8000ft at this stage. They certainly wouldn’t have launched from a commercial Iranian airport!
Something a lot of diagrams don't show but one way cruise missiles can be used is terrain following at <500 foot (sometimes as low as 100 foot) until they get close to their target at which point they "pop-up" to higher altitude in some cases ~5000 feet to acquire the target itself before coming in. So ignoring radar cross section (which is about 20x larger* for a 737 versus a typical older generation cruise missile as the US tends to use) an airline taking off from a nearby airport could look like a cruise missile on its final stage if it was aligned with a nearby military base. While other aircraft did take off from that airport around the same time and in theory any air-defence operators should be aware of its location this plane was bang in the middle of the window where they'd be expecting a US response to happen if it was a direct and immediate response so probably in the window where operators had the itchiest/nervous trigger fingers.
Throw in that these operators possibly don't have real combat experience and that the computers on a lot of AA stuff belong at best in the 80s often a couple of decades before that and it certainly isn't like in the movies when it comes to target acquisition they also probably had less of an idea of what was going on even than those of us who had access to the flow of information online even with the mix in veracity of what was being reported.
In theory Iran should have a command structure and not relying on operators at individual facilities to identify targets deep in their territory but cruise missiles are often designed to penetrate deep with as little warning as possible so they might have been running "hot" with the system at it's most ready to fire state and some degree of autonomy over shooting.
In tense situations like these organisation/communication tends to break down, this is when you tend to separate those with actual combat experience from those with just training and in the break down of communication some might start acting on their own initiative believing that an attack is underway and responsible for loss of effective communication, etc.
* It is bigger than that physically but not represented that way on older generation hardware.