At some point the cohort of militant prisoners will have to be freed

The irony that Usman Khan, who killed two people before being shot dead on London Bridge by police, had been attending a conference on prisoner rehabilitation only minutes before launching his attack is obvious.

Less apparent is the lack of surprise with which that particular element of the attack will have been greeted by many working on extremism and counter-terrorism.

States face one of their thorniest problems when one of their citizens is identified and located as a threat by security services.

One extreme option is to kill them – Anwar al-Awlaqi, a US citizen and radical preacher who was an influence on Khan, was killed in Yemen in 2011 by a drone strike ordered by President Obama. A more common response is to process them through the criminal justice system. Khan was found guilty of terror offences, including plotting to attack the London Stock Exchange in 2010 and jailed.

One key question is whether to segregate extremists or keep them with the rest of the prison population. The choice is between exposing ordinary prisoners to radical ideologies, or allowing hardened and experienced actors to network, plot and reinforce their existing views. No one has come up with a clear answer to this dilemma.

Then there is a question of release. There are three well-known and high-profile examples of what can go wrong here: Ayman al-Zawahiri, the current leader of al-Qaida, was incarcerated in Egypt following the assassination of President Anwar Sadat in 1981; Abu Musab al-Zarqawi was freed in an amnesty in 1999 in Jordan and went on to found al-Qaida’s branch in Iraq; and Abu Bakr al-Baghdadi, the late leader of Isis, whose time in Camp Bucca, a vast prison for suspected militants set up in Iraq by the US after the 2003 invasion, was critical to his rise. All three were set free because they were no longer thought to be a threat. In each case, this proved to be a tragic error.

Usman Khan was originally classed as never to be released unless deemed no longer a threat, but this condition was later lifted. He was released on licence in December 2018.

Clearly keeping all those convicted of any terrorism-related offence in prison indefinitely raises a host of legal, moral, ethical, political and practical questions. So some will always have to be released at some point.

Twenty, even 10, years ago, this was not much of an issue. But the sudden surge of Islamic militant violence in the aftermath of the 9/11 attacks and the Iraq war led to a new cohort of convicts facing terms of five to 15 years. Many have now been freed, or will be very soon.

A Guardian analysis last year showed that more than 80 of the 193 sentences for terrorism offences between 2007 and 2016 in the UK ran out by the end of 2018. That is far too many people for stretched security services to monitor permanently.

If these individuals were successfully rehabilitated – the topic under discussion when Khan launched his attack – there would be no problem. But even if they were adequately funded, deradicalisation programmes have had only very patchy success in recent years. There is no silver bullet for preventing recidivism.

Like so much of counter-terrorism, the result is a messy compromise between the often conflicting demands of the public, their elected representatives, officials, the law and many others. Inevitably, mistakes are made. And equally inevitably, people then die.

Jason Burke is the author of four books about Islamic extremism