Does the constitution of the US extend its protections to—
- legal aliens in the US (e.g. visitors from overseas), and
- illegal aliens in the US (e.g. someone who has stayed beyond their visa's validity)?
The answer is "it depends on the protection."
Even illegal aliens are afforded certain rights by the US Constitution. For example, that fact is one of the reasons for the prison in Guantanamo Bay.
Another consideration, for protections or rights that are available to citizens but not to aliens, is that the determination of citizenship or alienage must be subject to the right of due process. Without that, the executive branch of government would be able to, for example, remove or exclude anyone from the United States, or commit anyone to indefinite immigration detention, simply by asserting that the person is an alien, without review by the judicial branch.
There is a discussion, with references, here: https://www.law.cornell.edu/wex/alien. This mentions the fifth and fourteenth amendments, as well asthe fourth, as applicable to aliens.
Pertinent quotations (emphasis added):
Aliens also receive treatment very similar to the treatment that U.S. citizens receive in the context of the judicial system. For instance, the Fifth and Fourteenth Amendments of the United States Constitution apply to aliens residing within the United States. As such, the courts guarantee aliens the right to due process of law and equal protection of the laws. Courts have generally construed the Fourth Amendment as applicable to aliens as well. The Fourth Amendment prohibits the government from conducting unreasonable searches and seizures.
Congress has the preeminent power in terms of passing statutes that regulate immigration and alienage. Consequently, the United States Constitution enables Congress to delineate the rights, duties, and liabilities that accompany legal immigrant status. Congressional power in this realm, however, must comply with the qualification that any law resulting in disparate treatment between aliens and citizens must bear some relation to a legitimate goal impacting immigration law. When a law treats an alien differently from a U.S. citizen, courts treat the law as inherently suspect and apply strict scrutiny when considering the law's constitutionality.
States possess the power to confer additional rights on aliens within their respective jurisdictions. While states may not pass regulations affecting aliens that directly conflict with federal laws or the U.S. Constitution, states may pass other regulations if they bear some rational relationship to a legitimate state interest.
State law controls the right of an alien to hold real property in the particular state. Under common law, the alien had property rights similar to those of citizens. Currently, most states have enacted statutes following the common law, but a few have forbid aliens, ineligible for U.S. citizenship, from holding or acquiring real property. These laws have resulted in some successful challenges by aliens who claimed the laws were unconstitutional.
When invoking federal question jurisdiction, federal statutes provide aliens with access to the federal court system in the following three scenarios: allegations of civil rights violations by the federal government, allegations of Equal Protection Clause violations by the federal government, and allegations of violations of the Refugee Act of 1980.
A strict reading of the text sheds some light on the matter. For example, many constitutional rights are specified by limiting the power of congress; such a limitation applies to all people under the jurisdiction of federal law. For example, the First Amendment:
Congress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech, or of the press; or the right of the people peaceably to assemble, and to petition the Government for a redress of grievances.
Similarly, some rights explicitly granted by the constitution are typically granted to "the People," without reference to nationality. The Fourth Amendment:
The right of the People to be secure in their persons, houses, papers and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.
(The question of whether "the People" implies "of the United States" may explain the qualifier "generally" in the sentence above discussing applicability of the Fourth Amendment.)
Some rights are granted specifically to "persons"; the courts appear to have concluded that this applies to everyone regardless of nationality. The Fifth Amendment:
No person shall be held to answer for a capital, or otherwise infamous crime, unless on a presentment or indictment of a Grand Jury, except in cases arising in the land or naval forces, or in the Militia, when in actual service in time of War or public danger; nor shall any person be subject for the same offence to be twice put in jeopardy of life or limb; nor shall be compelled in any criminal case to be a witness against himself, nor be deprived of life, liberty, or property, without due process of law; nor shall private property be taken for public use, without just compensation.
Finally, some rights are expressed as procedural rules applying to the courts. As with limitations on congress, these apply to anyone who is party to a relevant action. For example, the Sixth Amendment applies to "all criminal prosecutions":
In all criminal prosecutions, the accused shall enjoy the right to a speedy and public trial, by an impartial jury of the State and district wherein the crime shall have been committed, which district shall have been previously ascertained by law, and to be informed of the nature and cause of the accusation; to be confronted with the witnesses against him; to have compulsory process for obtaining witnesses in his favor, and to have the Assistance of Counsel for his defence.
The Seventh Amendment applies to all "suits at common law":
In suits at common law, where the value in controversy shall exceed twenty dollars, the right of trial by Jury shall be preserved, and no fact, tried by a Jury, shall be otherwise re-examined in any court of the United States, than according to the rules of the common law.
I would argue that only second amendment right is restricted. The Supreme Court systematically interpreted we the people to include aliens. (I prefer the term non-citizens.) See United States v. Verdugo-Urquidez, 494 U.S. 259, 265, 271 (1990)( Supreme Court said that “the people” refers to those “persons who are part of a national community,” or who have “substantial connections” to the United States.10 The touchstone was not citizenship, but the extent of one’s connection to this country.)
Please read Harvard Law review article on indepth information on this topic. https://harvardlawreview.org/wp-content/uploads/pdfs/vol126_the_people_in_the_constitution.pdf
I would argue that only the second amendment right is restricted. And only as to those present illegal.
See Bridges v. Wixon, 326 U.S. 135, 161 (1945) (Murphy, J., concurring) ("The Bill of Rights is a futile authority for the alien seeking admission for the first time to these shores. But once an alien lawfully enters and resides in this country he becomes invested with the rights guaranteed by the Constitution to all people within our borders. Such rights include those protected by the First and the Fifth Amendments and by the due process clause of the Fourteenth Amendment. None of these provisions acknowledges any distinction between citizens and resident aliens. They extend their inalienable privileges to all 'persons' and guard against any encroachment on those rights by federal or state authority."
“There are literally millions of aliens within the jurisdiction of the United States. The Fifth Amendment, as well as the Fourteenth Amendment, protects every one of these persons from deprivation of life, liberty, or property without due process of law. Even one whose presence in this country is unlawful, involuntary, or transitory is entitled to that constitutional protection.” Mathews v. Diaz, 426 U.S. 67, 69, 77 (1976) (citation omitted); see also, e.g., Shaughnessy v. United States ex rel. Mezei, 345 U.S. 206, 212 (1953) ("It is true that aliens who have once passed through our gates, even illegally, may be expelled only after proceedings conforming to . . . due process of law.")
"No less a burden of proof is appropriate in deportation proceedings. The immediate hardship of deportation is often greater than that inflicted by denaturalization, which does not, immediately at least, result in expulsion from our shores. And many resident aliens have lived in this country longer and established stronger family, social, and economic ties here than some who have become naturalized citizens. We hold that no deportation order may be entered unless it is found by clear, unequivocal, and convincing evidence that the facts alleged as grounds for deportation are true." Woodby v. INS, 385 U.S. 276, 286 (1966).
The short answer is "it doesn't".
The constitution guarantees rights to "citizens". But with the law, there is rarely a simple black and white answer. Legal aliens are afforded certain protections, similar to, but not based on the constitution. Those protections would be defined in the framework of the immigration provisions that allow their presence in the country. This has not been my area of practice, but I would start with the Federal statute title governing immigration and then expect to find the details in the Code of Federal Regulations (both online).
As for illegal aliens, there are no constitutional protections and no protections afforded legal visitors, but that does not mean there are no protections. Here treatment is generally specified by Treaty, and in the absence of a treaty, general convention (i.e. the U.N. Convention of Treatment of Prisoners, etc..) that specify the minimum common treatments afforded anyone anywhere among developed nations. That minimum treatment can vary wildly (compare treatment in the U.S. with that provided in ISIS controlled areas of Iraq)