I think this death was meant to be the catalyst for the team to truly form and live up to it's name. There was someone for them to avenge.
The story sort of demanded it, though pretty standard plot device
in team coming together type stories, reason to hate the villian, etc.
That it was a rather beloved character made it impactful rather then something quickly contrived with some new character we didn't care about or would feel no loss... OH man they killed our pal... Bob! Man Bob was our pal and were mad now.
These characters live a very dangerous life, sacrifice is part of the expectation. Someone is going to get bit sooner or later. So a reminder of that now and then raises the stakes of our emotional investment in what goes on up there on screen.
Now did anyone really think Stark was going to die?
Well, probably not, but it probably helped that someone did earlier
to make us worried.