The Afghan president, Hamid Karzai, has demanded the return of Afghans held prisoner by the UK military in Helmand, giving London a two-week deadline that is legally impossible for the government to meet.

Last year UK courts banned the government from transferring the prisoners to their own justice system because of widespread torture in Afghan prisons.

This month the defence secretary, Philip Hammond, announced that Kabul and London had agreed safeguards to protect prisoners from torture, and handovers would start after three weeks.

The delay is a requirement to allow for any legal challenges to the decision, and is almost certain to stretch far longer, as lawyers acting for the prisoners have said they will challenge the decision in court.

But Karzai has demanded custody of the prisoners by 22 June. His spokesman said the British legal system should not be used as an excuse to delay the handover.

"We are living in Afghanistan and we are talking about Afghans detained on Afghan soil and held in Afghanistan. According to our laws this is a breach of sovereignty," Aimal Faizi told the Guardian. "The UK … is another country with its own laws and sovereignty, [which] don't mean anything here in Afghanistan."

His tough stance sets the stage for weeks or even months of confrontation, even though the UK insists it is as keen to transfer the prisoners as Karzai is to take custody of them.

"It is UK government policy to transfer UK-captured detainees into Afghan custody at the earliest opportunity. It has been the threat of UK court action that has prevented us from transferring detainees to the Afghan authorities since last November," the British Embassy said.

"We must be satisfied that they do not face a real risk of serious mistreatment or torture. As a matter of priority the UK has been working with the Afghan government to identify a safe transfer route."

Nato has periodically halted, then resumed, transfers of prisoners to Afghan authorities over torture concerns documented in detail by the UN. The Afghan government has also conceded there was torture in some jails, but has been persistent in calling for control of all Afghan prisoners detained domestically.

Karzai had previously focused his ire on the US forces, who held a far larger number of people in a more notorious prison attached to the Bagram airbase.

This year the US handed over the vast detention complex it had built and originally run. The UK says the men held in Helmand will be sent to this jail, which is large enough to manage all stages of detention, and open to UK monitoring to ensure there are no abuses.

"The facility at Parwan also includes a justice centre and is a properly resourced national facility at which both investigations and prosecutions can take place. There is no need, therefore, to transfer detainees to other facilities."

But lawyers say previous agreements to keep prisoners in jails where the UK could monitor them for signs of torture were flouted by the Afghan government and there was nothing to suggest the latest deal had any better safeguards.

"Our client Serdar Mohammed, who brought the case which provoked the moratorium on transfers [to Afghan authorities] last November, was transferred [between Afghan jails] and then tortured in exactly the way the MoD said would be impossible in an earlier case in 2010," said Richard Stein from the Leigh Day law firm.

"It is particularly concerning that the current proposals for transfer do not contain an express assurance from the Afghan authorities that there will be no onward transfers, even though the MoD accepts that NDS [National Directorate of Security, the Afghan intelligence service] facilities are not safe."

The drawdown of foreign forces means the fate of their prisoners is mostly a legacy issue. Almost all military operations are now joint with Afghan troops, who officially capture and process anyone detained during night raids or elsewhere.