The Supreme Court ruling that is most closely connected to this question is the ruling in the case of Boumediene v. Bush, which was decided in 2008. In that case, the Supreme Court ruled that even the “unlawful enemy combatants” held in Guantanamo Bay had the right to habeas corpus.
After the 9/11 attacks and the invasion of Afghanistan, the US government set up a prison camp at Guantanamo Bay. It held the detainees there without charging them and without allowing them to petition for habeas corpus. In 2006, Congress passed a law making it essentially impossible for the detainees to petition for writs of habeas corpus.
In 2008, the Supreme Court decided the Boumediene case. In that case, it ruled that the US had to extend the right of habeas corpus to the unlawful enemy combatants captured in the war on terrorism.