Iran has it's own internal politics and factions it needs to appease.
This is true of most countries too.
The US invasion of Iraq had far more to do with internal politics than it did with any actions of Saddam.
The current elected leader of Iran was actually the concillatory to the west candidate, elected when tensions were not quite as high.
Now that tensions are high, he has to prove he's not too weak to his own constituency, as the Persian people come together under what they consider to be an unjust attack.
Again, this is true in general for most countries. Foreign policy is driven far more by domestic politics then most people consider.
Their Oct 1 attacks were in response to the assassination of Nasrallah, in combination with a response to the assassination of a visiting diplomat in Tehran from a separate attack from Israel.
Iran agreed not to respond to the assassination because the US promised that if Iran didn't respond, the US would secure a peace deal for Gaza.
The fact that they delivered and the US didn't is well known to the Persian people, even if it isn't here. And, the lack of response was considered internally there as encouraging Israeli aggression.
The whole 'nothing is more important than the US election' is far less accurate than you think it is.