Is there any practical way to bring the military under accountability
in Pakistan while keeping their morale intact?
The path most likely to produce a more accountable military while keeping their morale intact (not necessary the best outcome globally, but what the question is asking) may be to:
(1) the make the military bigger and more high tech,
(2) encourage the military to take steps that help to develop a very professional and competent civil service that it feels comfortable turning over power to eventually, and
(3) encourage the military to help facilitate the development of one or more political parties that are not corrupt and vet their leaders for competence to develop, before turning over power more completely to civilians. Ideally, the parties would also have an unimpeachable publicly perceived commitment to Pakistan's Islamic identity as well.
Parts (2) and (3) of this plan are what the U.S. military establishment, when it is in another country, calls "nation building" (i.e. "a significant undertaking that governments employ to develop political, economic, security, and social institutions in other countries—especially those emerging from conflict."). RAND has a handbook telling policy makers how to do it, in general (which I don't purport to be relying upon in this answer).
One way to address (2) and (3) would be to develop a Pakistani equivalent to the French École Nationale d'Administration, an elite university which trains an outsized share of the top civil servants and many prospective politicians in France, perhaps as a sister university to its war colleges, or to its leading Islamic higher educational institutions, or both. It should have highly uncorrupt meritocratic admissions and grading policies.
Another institutional approach to advance objective (3) would be to strengthen political parties relative to the grass roots, so that they have the power to vet their leaders and officers better, in the tradition of British political parties, for example which are very strong vis-a-vis individual MPs. Strong parties and weak MPs also make efforts to corrupt individual MPs less worthwhile.
A third tool would be with respect to military HR policies designed to break up people with family or clan or similar ties into different units. The naturally dovetails with objective (1). Merit based exam promotions systems might be another good start on this front.
Key observations supporting this conclusion:
Military coups are correlated to the absolute (not relative to population) size of the military. This is because this influences how many military officers need to be co-opted to gain de facto control of the military. It is easier to organize a conspiracy of 12 generals and admirals to overthrow a civilian government than it is to do so in a military with 200 of them divided into many competing factions. The bigger the military is, the harder it is to mobilize it unofficially and contrary to civilian orders. This is very viable in Pakistan because while it has a moderately large military, it isn't particularly mobilized militarily as a country in terms of troops per capita or percentage of GDP spent on the military.
Coups are harder to facilitate without behind the scenes informal connections of extended families, clans, or similar close bonds beyond the senior officer's formal roles in the military. It is easier to undermine nepotism and informal ties in a larger military bureaucracy.
A more powerful military makes the threat to Pakistan from rival India seem less existential.
Military juntas usually voluntarily relinquish power to some sort of civilian regime (not necessarily a terribly democratic one) before too long, because soldiers soon find out that they aren't good at running a civilian governmental administration and have no desire to do it. Running the civilian government also tarnishes their reputation and popularity if they do a poor job of it (something that is inevitable in the long run because military officers aren't trained to do civilian governance jobs). The military has done so repeatedly in Pakistan's rather short history.
The military (just like any monarch or dictator) wants their country to succeed so long as it doesn't undermine their power. A good professional civilian administration makes the country prosperous which increases tax revenues which makes more funds available for the military and military officers like a larger military. What top military officer isn't an institutional empire builder at heart?
Most military coups are driven by a military officer perspective perception of incompetence and corruption in the civilian administration which makes their intervention necessary and desirable because they can do better than this very low bar. Pakistan's history is consistent with this pattern. So, this suggests that non-corrupt, competent senior civil servants and politicians are needed to facilitate a handoff that the military can trust will work out. If the military trusts the civilian leadership to do the right thing, accountability won't be nearly as much of an issue. Military assertions of dominance over civilian leaders bucking accountability to civilian leaders arises because military leaders don't trust them.
The military will feel threatened by and distrust civilian leaders if its resources are reduced, while simultaneously having fewer people who need to be mobilized to carry out a coup.
Pakistan has a smaller cadre of highly professional and skilled top level civil servants relative to its population, than India or many other countries with more accountable military forces.
A higher tech military is forced to be more meritocratic in its HR practices, overcoming nepotism to some extent, in order to have people who can operate these advanced systems.
Strong informal family/clan/etc. ties are a major driver of corruption in Pakistan that undermines its formal institutions. But the military is less subject to this than some other institutions in Pakistan.
China and Iran are examples of regimes that have followed this route to become less bad than they were in the 1970s and early 1980s, and to have more accountable military forces than they did then.