Sometimes it appears as if, over the past ten years, the government has been actively trying to destroy the whole criminal justice system. It’s like an evil experiment: impose a 20 per cent cut in the prisons budget, meaning a 26 per cent reduction in the number of operational front line staff — then sit back and see what happens. What happened was predictable, with disastrous consequences for both inmates and the public. As a previous Conservative home secretary once said, our prisons became places that ‘make bad people worse’.

Imagine a young man like Sudesh Amman arriving in prison after his first offence. He was already a drug user, known to have a cannabis habit. He was mentally unstable and radicalised by Islamist propaganda. He entered a prison that’s usually overcrowded, frequently filthy and with too few staff struggling just to keep people alive (themselves included) from one end of the day to the other.

Inside, all of his problems are not addressed but exacerbated. In most prisons there’s a rampant drugs economy that destroys lives and drives much of the violence. It makes the task of reforming offenders near impossible. The money to be made from drugs inside is extraordinary. The predators can access their customer base without leaving their cells. Mobile phones actually designed and sold for their ability to be stored where the sun don’t shine have handy apps to transfer the cash to the dealers. It’s also convenient for the dealers that many of the captive consumers have huge unmet needs with mental health problems. Finally, charismatic hate preachers are in close proximity to credulous, violent, addicted young men in search of meaning and excitement.

The details of Amman’s incarceration and early life are slowly emerging and they suggest a loner and a misfit, infatuated with death, who was eager for martyrdom to make sense of a failed and futile existence. This is a depressingly familiar profile for lone actor terrorists the world over, and it is often associated with mental illness. And this matters. The relationship between mental or developmental disorders and terrorism is frequently drowned out — either by commentators who see conspiracy to obscure the ideological origins of the crime, or by those who fear all mentally ill people will get labelled as dangerous.

Such concerns are understandable — but those killed by insane terrorists are just as dead as those dispatched by ‘rational’ killers. Amman’s former cell mate at HMP Belmarsh has described him as someone who was ‘definitely insane and he never hid his intentions, so it’s crazy how he even got out of jail’.

Amman’s mother has claimed that her son was effectively brainwashed by material he viewed online in prison. It’s still possible to be astonished at this. HMP Belmarsh is a relatively modern high-security prison housing a number of terrorists. It has a permanent presence of counter-terrorism officers within its security and intelligence department. It is relatively well-resourced. But as ITV’s Welcome to Belmarsh documentary showed, it needs the full attention of staff to struggle to contain 68 street gangs and entrenched use of psychoactive drugs.

Who the hell would work in a place like this? Good question. While the gigantic Grayling-sized hole in the staff bucket has lately started to fill with emergency recruitment of new staff, they emerge from one of the shortest training courses in Europe to work in one of the most hostile environments outside a war zone. An Afghan veteran prison officer recently said that he had felt safer in Helmand. Little wonder then, that on the latest figures, over half of all prison officers hanging up their keys have less than two years’ service. When stacking shelves pays more than being the state’s punchbag, it’s not hard to understand why.

When I wrote my review of Islamist extremism in the criminal justice system in 2016, my team and I were unanimous that a prison solely for terrorists was not the answer to the threat we identified. We took the view that the only extremists who should be separated were the hate preachers: those likely to inspire others with extreme ideology. We recommended they should be cut off from their targets for as long as they persisted in their activities. We were mindful of the lessons from the past from Northern Ireland, but not hamstrung by them.

Now, I’m not so sure. We need secure and stable prisons that are fully in the control of the state: and too many prisons now fail this test. We cannot have environments where people like Usman Khan and Sudesh Amman degenerate into killing machines. We can’t tolerate a system where the sole product of their time behind bars is the dehumanisation of themselves and others. It is increasingly hard to make the case for a ‘good prison’ that puts brawlers and gangsters up in close proximity to death cultists.

What would a terrorist prison look like? There are plenty of examples around the world to draw from. Many aren’t good. The main argument for dispersing terrorist prisoners across a number of reinforced prisons (as we currently do) is that this reduces the potency and capability of the most dangerous. But dispersal was designed to deal with serious organised crime syndicates, not networked 21st-century jihadists with hinterlands of supporters in each of the six prisons they are likely to end up in. Metastasising the cancer of violent extremism across our prison system doesn’t seem to be the right response to a movement whose modus operandi is global revolution through recruitment of new blood.

But in the current environment, it’s unlikely we will move to jihadi jails anytime soon. In the meantime we must deal with things as they are. We need a framework for sentencing and releasing prisoners and this is in progress. The quantity of years given to an extremist is less important than the quality of the incarceration. Of the 82,000-odd prisoners, only about 220 are terrorists, with hundreds more screened after being deemed at risk of radicalisation. We need to be more assertive in managing the challenge they pose — from the start of their custody to their resettlement in the community.

All the various arrangements for the supervision of terrorist offenders ‘in the community’ (i.e. outside of prison) use structures and agencies that are philosophically and organisationally unsuitable for the management of this threat. There should be one terrorist prisoner management service, covering individualised treatment programmes, risk assessment, release decisions and resettlement supervision. People who go into the streets and stab strangers with impunity are in no conventional way rational. So we need to step up the surveillance, treatment and protection of those whose psychological disorders may predispose them to strike. No more generic, psychosocial interventions invented by well-meaning professionals.

And finally: you can’t defeat Islamism without Islam. We need an urgent step change in the recruitment, deployment and involvement of moderate and modern Islamic scholars to take on this fight. Indeed, we need to seek the support of communities when terrorists are released from prisons, working in partnership with the various protective services. It needs to be a joint effort.

What of those who can’t (or won’t) surrender ideas that are completely antithetical to our national values, even to what it is to be human? We must find ways to keep the door open for them to change. We’ve no clear idea about the relationship between time and desistence for this new generation of terrorists. But let’s be straight: that open door needs to be behind high walls and in the confines of prison custody. If necessary: for ever.

An Afghan veteran prison officer recently said that he had felt safer in Helmand