Military intervenes because politicians give them space. They cant intervene if politicians are honest and competent.
Right now, Pakistan has a so called democratic government. But which aspect of state the military is not taking part in? Flood relief, war on terror, earthquake rescue, foreign policy and law and order in Karachi. All these all civilian mandates but civilian set up does not have capacity.
The lack of capacity is due to corruption and incompetence. Karachi is a purely civilian issue. What we see there is destruction of institutions. Lack of prosecution, politicized police and ruling parties involved in theft and murder has rendered the government dysfunctional. In this space, the army step in to stabilize Karachi.
Karachi is just one example. These politicians have systematically destroyed bureaucracy. Result of this political patronizing of every aspect of state craft has left the country facing self made crises. Its because of corruption and political patronizing that institutions have decayed and Pakistan as state failed to deliver.