Few things:
#1. Establishment is part and product of the society. If your society is in general corrupt and incompetent, than don’t expect it to produce Ibn Khaldun or Al-Khwārizmī.
#2. US spends $270 billion on it’s veterans every year. Pakistan is in a constant state of war, but send it’s veteran home after they get injured both physically and mentally and tell them to contact Fauji foundation. Govt don’t provide funding to fauji foundation, they run business to generate money. Physical wound can heal but unseen mental wound ruin families. My father was a veteran of 65 and 71 war but other than Red cardboard 2 page mini Fauji foundation booklet (for medical), which he almost never used. There were no benefits provided to him. He was never diagnosed or provided with any benefits. Now when I am a veteran myself, I realized my father most probably had PTSD all his life, which he was never diagnose, given treatment or compensation for. In US veterans are compensated for every, scar, mental or physical injury for rest of their life. Read up on PTSD, and how it effect life.
#3. To have a function military, country have to make sure the families of soldiers are provided with decent accommodation. They are safe when males members of their family are away. City like Karachi, where foreign agents are targets killing at will, you cannot blame establishment for build gated communities. Otherwise it will erode the effectiveness of military. You Top brass need to have certain level of dignity and retirement benefits that they don’t get compromised by foreign intelligence or don’t think twice about performing their duty.