ISLAMABAD—Pakistan’s judiciary is stepping up to curb the country’s armed forces, an unexpected challenge for a military that has extended its power in recent years behind the scenes.

A series of recent court rulings has interrupted a period of growing political clout for the military after the 2018 election of Prime Minister Imran Khan, who is supported by the armed forces, and the 2017 ousting of former Prime Minister Nawaz Sharif, who had clashed with them.

...