It's quite simple actually, and very pragmatic and logical.
Azerbaijan for years has been working with Israel against Iran, and have purchased billions of dollars worth of Israeli military equipment, to in the future, use against Iran. Supposedly this is a Muslim country. This extensive relationship, including covert relationship has been a thorn on the side of Iran that has tolerated it for many years now.
After Khamenei himself said that Karabagh was legally and rightfully Azerbaijan's, Aliyev decided to block the Goris-Kapan road, and arrested Iranian (Azeri speaking) truck drivers, and arrest a few of them as well. In addition, Aliyev said any goods that are traded between Armenia and Iran will be taxed. In essence, Azerbaijan wants to cut off the Iran-Armenia border, and cut off an important trade route of Iran. Is that not supposed to be perceived as a threat? This whole story is a story about a small country repeatedly poking it's neighbor, and after being poked 1000 times, including allowing its land to be used by Israeli Mossad agents for sabotage operations, it seems that a reaction is happening.
In addition, Azerbaijan may be a base used by Israel to attack Iran, such possibility has been around since 2012. Now with all this piling up, certain Azerbaijani officials have made it quite apparent that they want to "wipe Iran off the map" based on a Turkish newspaper. And such, you can see that Iran has lost it patience here. I don't think I need to remind you that Azerbaijan is not a Muslim country, it is a irreligious and secular country who purchases their weapons from Israel. Theirs probably some other points I've missed here but I'm sure others can elaborate.