There is an Oath of Enlistment for the military where the enlistee vows to
support and defend the Constitution of the United States against all
enemies, foreign and domestic; that I will bear true faith and
allegiance to the same; and that I will obey the orders of the
President of the United States and the orders of the officers
appointed over me, according to regulations and the Uniform Code of
"The laws" are not mentioned.
The thing known as the Oath of Allegiance is spelled out in 8 CFR 337.1, and currently states:
I hereby declare, on oath, that I absolutely and entirely renounce and
abjure all allegiance and fidelity to any foreign prince, potentate,
state, or sovereignty, of whom or which I have heretofore been a
subject or citizen; that I will support and defend the Constitution
and laws of the United States of America against all enemies, foreign
and domestic; that I will bear true faith and allegiance to the same;
that I will bear arms on behalf of the United States when required by
the law; that I will perform noncombatant service in the Armed Forces
of the United States when required by the law; that I will perform
work of national importance under civilian direction when required by
the law; and that I take this obligation freely, without any mental
reservation or purpose of evasion; so help me God.
It is administered as part of the naturalization process. Para (c) states the presumed obligations of that oath:
A petitioner or applicant for naturalization shall, before being
naturalized, establish that it is his or her intention, in good faith,
to assume and discharge the obligations of the oath of allegiance, and
that his or her attitude toward the Constitution and laws of the
United States renders him or her capable of fulfilling the obligations
of such oath.
A finding of unconstitutionality by the Supreme Court results in a certain level of legal chaos. If a court "discovers" that a law is unconstitutional, that means that for such-and-such reason, the law conflicts with the Constitution, we know that the Constitution is the supreme law of the land, and therefore the purported law (or portional thereof) is not and was not a law.
However, recall that death penalty laws were (in their form at the time) declared unconstitutional in 1972, by Furman v. Georgia. Thousands of people had been previously executed under various state laws: the execution was legal at the time and the executioner(s) were not subject to prosecution for murder because murder statutes refer to unlawful killing whereas a court-mandated execution is a lawful killing. Furman did not then expose thousands of penal-system agents to criminal liability for acts which were "unknowingly illegal".
A person will not be penalized for failing to adhere to the Oath of Allegiance as part of the naturalization process: but they may be penalized for performing a generally-forbidden act. The Oath of Allegiance isn't "enforceable" although it is mandatory to take the oath, so there is no way to tell how the courts would interpret this issue.