What is habeas corpus, and where is it guaranteed by law?

Habeas corpus (more fully, habeas corpus ad subjiciendum) is a Latin term for a centuries-old legal protection. The writ of habeas corpus guarantees that a person who has been detained (arrested) has the right to go before a court and have the court decide whether the detainment or imprisonment is legal. If the court finds that a person was detained illegally, that person must be set free.

Habeas corpus is mentioned in the U.S. Constitution in Article 1, Section 9:

The privilege of the Writ of Habeas Corpus shall not be suspended, unless when in Cases of Rebellion or Invasion the public Safety may require it.

Notice that this section allows for the suspension of habeas corpus, a point that came into play in the nineteenth century. In April 1861, early in the Civil War, President Lincoln suspended habeas corpus in order to restrain southern sympathizers (especially in the border states) and ultimately to keep Maryland from seceding from the Union.

Confederate President Jefferson Davis also suspended habeas corpus, enacting martial law.

Lincoln's suspension of habeas corpus raised a big legal ruckus at the time, but Congress eventually agreed with him and passed the Habeas Corpus Suspension Act of 1863. That Act remained in place throughout the rest of the Civil War; President Andrew Johnson repealed it on December 1, 1865.

Habeas corpus saw further problems five years later. During the Reconstruction following the Civil War, a number of groups, including the Ku Klux Klan, arose in the South to oppose the government's changes. Such groups were routinely violating the rights of newly freed slaves, and local law enforcement was powerless or reluctant to control it.

So Congress passed the Force Acts of 1870-1871, one of which was called the Civil Rights Act of 1871. This Act allowed the President (Ulysses S. Grant by this time) to suspend habeas corpus if conspiracies against the authority of the federal government became so violent that normal mechanisms could not control them. Grant exercised this power on a number of southern counties in the following years.