"American Taliban" John Walker Lindh wanted to memorise the Koran, his Pakistani teacher said.

A Pakistani religious teacher who spent six months with "American Taliban" John Walker Lindh has hailed his release, describing him as a "good person" who became upset over the situation in Afghanistan, Kashmir and Palestine.

Lindh symbolised betrayal for the US when he was captured, bearded and dishevelled, while fighting for the Taliban in the Afghan city of Mazar-i-Sharif in 2001.

His release from prison on Thursday -- three years before the end of his 20-year sentence -- has re-awakened memories of the September 11 attacks and underscored the tragedy of the US invasion of Afghanistan, where civilians are paying a deadly price as the war grinds on.

President Donald Trump said he was upset about the release, but government lawyers had told him there was no legal way to keep him in prison.

"We'll be watching him and watching him closely," Trump told reporters.

But Mohammad Iltimas, who taught Lindh for six months at a Muslim school near the Afghan border in Pakistan's northwest, said he was happy to hear of the decision to release him.

"He was such a pure person, such a positive-thinking man," Iltimas told AFP.

Iltimas said Lindh came to his school -- the Madrassa Arabia Hussania, outside the city of Bannu -- in December 2000, and stayed until May or April of the next year.

"He wanted to memorise the Koran," he said, describing how Lindh could often be seen listening to Koranic verses on a tape recorder or learning Pashto.

"He was such a good student, pious and focused on his studies, I never saw him sitting idle. He was not interested in sports. He was such a serious and committed person to his cause."

Lindh was "upset over the situation in Afghanistan, Kashmir and Palestine", said Iltimas.

At the time, the Taliban regime which controlled most of Afghanistan was engaged in a bloody fight with the rebellious Northern Alliance.

Soon the madrassa student enlisted in the Taliban's ranks.

After the United States intervened in Afghanistan following the September 11, 2001 attacks, Lindh was one of hundreds of Taliban fighters captured by Northern Alliance forces on November 25.

He revealed his American identity to two CIA officers in the city of Mazar-i-Sharif.

One of them, Johnny Micheal Spann, was killed in a prisoner revolt hours after he interrogated Lindh, making him the first American killed in post-9/11 conflict in Afghanistan.

'Too brave or too stupid'

Mazar residents who remembered Lindh described to AFP their shock on hearing that an American had been captured fighting for the Islamist militants.

"People were asking how is that possible," recalled 40-year-old resident Khayber Ibrahimi.

"I think he must have been too brave or too stupid to have gone with the Taliban," he told AFP.

In July 2002 plea deal, Lindh admitted charges of illegally aiding the Taliban and carrying weapons and explosives.

By most accounts, he clung firmly to his faith throughout his imprisonment.

An internal 2017 report from the US National Counterterrorism Center, obtained by the Foreign Policy website, said that Lindh "continued to advocate for global jihad and to write and translate violent extremist texts".

The claim was not supported by public evidence.

Iltimas told AFP that Lindh had written him from prison, although AFP was unable to immediately verify the claim.

When Lindh left for Afghanistan, Iltimas said, he left some of his possessions behind at the madrassa, claiming he would return.

"I still have that stuff -- his briefcase, books, shoes, clothes, notebooks," Iltimas told AFP.

"People at the time used to ask me if I had changed him into a jihadi," he said.

"I always replied to them that I turned him to education, and changed him as a scholar."

Now 38, Lindh will settle in Virginia under strict probation terms that limit his ability to go online or contact any other Islamists.

In Afghanistan, where he was captured, the Taliban are once again resurgent, Afghan civilians desperate for peace, and the US eager to escape what has become the longest war in its history.