A federal judge has temporarily halted the planned execution of Nidal Hasan, who was convicted of killing 13 people in a 2009 attack at Fort Hood in Texas. The execution had been scheduled for Thursday.

On Monday, US District Judge Anthony Mattivi granted Hasan’s request for a stay. “Without a stay the Army will execute him before any court can consider his claims,” Mattivi wrote.

Hasan has said he plans to file a habeas corpus petition challenging the legality of his detention and execution. He was represented at Monday’s hearing by members of the American Civil Liberties Union (ACLU) and its Capital Punishment Project. His lawyers argued that the 62 days between President Donald Trump’s approval of the execution and the scheduled date were too short to prepare the petition.

Trump approved Hasan’s execution by firing squad, a decision revealed in early October. It would be the first time since 1961 that the US military had carried out such a punishment.

Mattivi’s ruling indicated Hasan’s defence team would argue that Trump and Defense Secretary Pete Hegseth used “unlawful command influence” and “bigoted animus” to fast-track the execution. Hasan also said the Trump administration failed to follow military regulations by notifying him of the execution three days after signing the order, without a chaplain or lawyer present.

Mattivi acknowledged the arguments and said more time was needed for court review. “At least one of the claims he previews – that unlawful command influence and animus drove the approval of his sentence – arose after military review ended, and no military court can now hear it,” he wrote.

The judge said judicial review was necessary even in cases that provoke strong public sentiment. “We are a nation of laws. Those laws protect everyone who comes before a court, including people convicted of the worst crimes,” Mattivi wrote. “They apply with the same force even when the public would prefer a different result. The rule of law must be jealously guarded, and cases like this one test it most.”

Hasan, a former US army psychiatrist, has admitted opening fire on soldiers on November 5, 2009, before his scheduled deployment to Afghanistan. The attack killed 13 people and wounded more than 30. A military court convicted him of murder and attempted murder in 2013 and sentenced him to death. The Supreme Court previously denied an appeal to overturn his conviction.

At Monday’s hearing, lawyers for the US government questioned why Hasan was filing a habeas corpus petition now rather than earlier. “This came right at the cusp of the execution, when he had all this time to challenge,” Assistant US Attorney Jared Maag said. ACLU lawyers argued that preparing a proper petition would take at least six months.

Hasan’s petition is likely to address recent events surrounding the planned execution. On October 7, Hegseth pledged that it would be made public, and the Department of Defense later announced it would be livestreamed. The prospect drew objections from religious officials, who said a public spectacle would violate the dignity of human life, and from critics who feared the footage could be used as propaganda by US adversaries.

Questions were also raised about executing Hasan in a wheelchair; he is paralysed from the waist down. Trump ultimately scrapped plans for the livestream. Hasan is being held at the Fort Leavenworth military base in Kansas.