Pakistan's supreme court on Monday forced the authorities to present seven men who vanished four years ago, apparently into the custody of Inter-Services Intelligence (ISI), in a case that tests whether the country's military's main spy agency is above the law.

The missing men hobbled into the court having been brought in ambulances to Islamabad from their places of detention by security officials, including ISI agents. The men – emaciated, bewildered and finding it difficult to stand or talk – were brought wearing handcuffs into the court, where they had an emotional reunion with relatives.

The men will remain in custody, but the court ruled that they must be held by civilian authorities until the case is decided – although they were still led away by a phalanx of plainclothes intelligence agents.

After the hearing, as he was being taken away, Abdul Majid, one of the detainees, broke down in tears. "Either take our life or let us go," pleaded Majid, 23, who said that he had not received medical care for his illness and had been getting little food. Majid had appeared in court carried a urine-filled colostomy bag in his hand, as a result of kidney problems.

A distraught detainee, Abdul Majid, is led away from the court. Photograph: Saeed Shah for the Guardian

"They picked me up from my shop. I was a businessman," he said as security officials tried to usher him away from media. "No one has ever explained to us why we are being held."

Majid was more fortunate than Abdur Saboor, one of his two brothers picked up at the same time from their printing business in Lahore. Last month, their mother received a call to pick up Saboor's body, which had been dumped in an ambulance parked outside the north-western city of Peshawar.

The men went missing in late 2007 and early 2008, seemingly picked up by intelligence agents suspecting them of involvement in terrorism. The men were all highly religious and many were associated with Islamabad's radical Red Mosque.

Eleven of them later ended up in a civilian jail, Adiala in Rawalpindi, from where, following court orders to let them go, they were abducted a second time, allegedly by the ISI. On the day they were due to be released in May 2010, as some 100 relatives waited outside Adiala prison to greet them, they were whisked away. Four of the men, including Saboor, have turned up dead in recent months, making the supreme court case urgent for the lives of the remaining seven.

"These boys are not terrorists," said Ghulam Murtaza, father of another detainee, Mazhar ul Haq, 35. "My son says he was being kept in a basement where he sleeps on the floor and it is very cold. All of them have lost so much weight."

Part of Haq's family lives in London, with two of his British relatives, who did not want to be named, in the court.

Chief justice Iftikhar Chaudhry ordered a report from the ISI and the military intelligence spy agency explaining what law the men were being held under.

Meanwhile, as well as trying to press its authority over the military, which commands the ISI, the activist supreme court has kept up it pressure on the government. Prime minister Yousaf Raza Gilani was formally charged with contempt of court on Monday , over his refusal to follow court orders to ask Swiss authorities to reopen a dormant corruption case against Pakistani President Asif Zardari. If convicted, Gilani would likely to be barred from office.