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

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

Hasan has indicated that 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.

Hasan’s lawyers argued that the 62 days between President Donald Trump’s approval of the execution and its scheduled date were too short to prepare a habeas corpus case. The ruling said his defence team would argue that Trump and Defense Secretary Pete Hegseth used “unlawful command influence” and “bigoted animus” to fast-track the execution.

Hasan said the administration did not follow military regulations when it notified him of the Thursday execution three days after signing the order, without a chaplain or lawyer present. Mattivi said the claims warranted time 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.

Mattivi also stressed the need for judicial review 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,” he 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.

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 carried out such a punishment. Hasan’s petition is likely to address recent events around the planned execution.

On October 7, Hegseth pledged that the execution would be made public, and the Department of Defense later announced it would be livestreamed. The prospect drew criticism from religious officials, who said a public spectacle would violate the dignity of human life, and from others who feared the footage could be used as propaganda by US adversaries. Questions were also raised about executing Hasan, who is paralysed from the waist down and uses a wheelchair.

Trump later scrapped the livestream plan. Hasan is being held at the Fort Leavenworth military base in Kansas.