It was a domestic political need immediately after the revolution; an external threat legitimizes the rule. India does it well. Then it found legs of its own; the US reaction to it, in no small part due to the interests of the Israelis and the Arabs, turned it into a feedback loop.
Add to that the Muslim religious circles' ridiculous insistence on fighting it out of our current situations. If you were to elect/select a religious party in Pakistan, the same will happen.
Left the Kashmiris high and dry though, despite the long history of support Pakistan provided them. Then there's the 90s between them and the Saudis across the region, including Pakistan. The Iranians did and continue to do what they need to for their own interests. Muslim interests have nothing to do with it. Pakistanis should take a page from them.