Haniyeh had been living in Qatar for decades, but went to Iran to attend the swearing in ceremony for Masoud Pezeshkian, Iran's newly elected president. I guess what really has protected Haniyeh all these years was less about whatever security he had and more about the fact that Israel has unofficial diplomatic relations with Qatar and they did not want to screw that up. Haniyeh must have thought that Iran could protect him in Tehran, but Israel has no diplomatic relationship to screw up with Iran.
This has triggered a lot of speculation about what this will mean about a Gaza ceasefire and potential hostage release. Haniyeh was negotiating such a deal with Israel with Qatar as the intermediary and in recent weeks people have been saying a deal is close. Now it is hard to imagine that Hamas would agree to any deal with Israel right after Israel killed their leader. That is good news from Netanyahu who gets to both brag that he took out Hamas' leader and does not have to face a hard decision about a ceasefire deal that might bring down his government. And of course, no ceasefire is terrible news for the people of Gaza. I don't think it (no ceasefire) is good for Israelis either as it is yet another reason, along with Israel's attack on Beirut yesterday, to fear there might be a wider regional war.
I also wonder what President Pezeshkian will do in response to this. He was the "more moderate" and "pro-western" candidate in the recent Iranian elections. This puts him in a really tight spot. Any country would feel they have to strike back after a missile strike on their capital.
UPDATE (8/1/24): So it wasn't a missile attack after all. It was a bomb hidden in a guest house two months before. It looks like what happened is Haniyeh had a guest house that he always used when he visited Tehran. Israeli agents somehow managed to plant a bomb in the guest house and just let it sit there for months, waiting for Haniyeh to come back. When they confirmed he was in the house for the presidential inauguration, they detonated the bomb.