Individuals who join the military are subject the provisions if the Uniform Code of Military Justice pursuant to Article I, Section 8, which provides that "The Congress shall have Power... To make Rules for the Government and Regulation of the land and naval forces." Also, the 5th Amendment of the US Constitution addresses this where, "except in cases arising in the land or naval forces, or in the militias, when in actual service in time of war or public danger." There are several "articles" that could speak to this issue, however, Article 88 Contempt Toward Officials is one that expressly prohibits a particular activity.
"ART. 88. CONTEMPT TOWARD OFFICIALS:
Any
commissioned officer who uses contemptuous words against the President, the Vice President, Congress, the Secretary of Defense, the Secretary of a military department, the Secretary of Transportation, or the Governor or legislature of any State, Territory, Commonwealth, or possession in which he is on duty or present shall be punished as a court-martial may direct."
"In United States v. Howe, an Army Lieutenant was convicted for carrying a sign during an antiwar demonstration that read Lets Have More Than A Choice Between Petty Ignorant Fascists In 1968 on one side and End Johnsons Fascist Aggression In Vietnam on the other side. Lieutenant Howe did not participate in organizing the demonstration, but merely joined it after it began. During the half-hour demonstration, Howe was off duty, in civilian clothes, and no one at the demonstration knew of his military affiliation. Howe came to the Armys attention only because a gas station attendant, who Howe had asked for directions, spotted the lieutenants sign and an Army sticker on his vehicle and subsequently notified the local military police.
Lt. Howe was sentenced to dismissal, total forfeitures, and confinement at hard labor for two years. The convening authority reduced the period of confinement to one year and otherwise approved the sentence. Three months and two days after his trial he was released from confinement under commandants parole."
Watch what you say: Speech limits under UCMJ