By the Constitution’s original meaning, the privilege of habeas corpus is guaranteed to all those in “allegiance” to the United States. “Allegiance” is an old technical legal term that includes both citizens and aliens legally in the country.
By successfully convincing a judge to issue a writ of habeas corpus, citizens, foreign visitors, and legal residents may obtain a hearing that may induce the judge to order a civilian trial. It matters not how heinous the crimes they are accused of. For example, a person charged with trying to blow up a building on behalf of a foreign power can be charged with treason. But while still merely accused, he is entitled to all the protections of due process, including a fair, public trial before a jury of his peers.
By the Constitution’s original meaning, habeas corpus does NOT apply if the Congress, as an incident to its war power, “suspends” the writ for a particular time and place. However, the Constitution says that Congress may “suspend” the writ only “when in cases of rebellion or invasion the public safety may require it.”
More on Sections 1021 and 1022 can be found here.