Turkey and Pakistan had a similar situation before Erdogan came to power.
The military and Judiciary banded together to ban Abdullah Gul from politics. The military staged a coup in 2016. However, gradually, Erdogan took control of the military, and now they have no visible influence over politics.
However, in Pakistan, the situation is not changing. The latest incident seemed to be the removal of PM Imran Khan's government.
Allegedly, the feud started because of the appointment of the ISI chief. The Army GHQ nominated Gen Nadeem Anjum as the ISI chief, and PM's office wanted to keep the sitting ISI chief Gen Faiz Hameed. Therefore, the army, allegedly, invited the opposition and told them to take necessary measures to remove Imran Khan.
The task was straightforward for them as IK didn't have an absolute majority in the parliament. The opposition spent 20 million PKR per person to purchase 20 dissidents from Imran Khan's party and convinced his coalition partners to call off their support. Therefore, the IK's government lost the majority in the parliament. A similar game was played in the provincial assembly of Punjab.
Allegedly, the Judiciary also helped the Army and the IK's opposition in that the Chief Justice took Suo Moto notice against the dissolvement of parliament (the dissolvement was in favor of PM IK so that he could avoid a no-confidence move) but stayed silent in the case of horsetrading of the opposition.
Now, my question is, why was it possible for Turkey to take control of its military, but Pakistan is yet to be successful? What is the fundamental difference between these two countries in this case?