Military bases are U.S. government property. Article 4, Section 3 of the U.S. Constitution provides as follows:
The Congress shall have Power to dispose of and make all needful Rules and Regulations respecting the Territory or other Property belonging to the United States; and nothing in this Constitution shall be so construed as to Prejudice any Claims of the United States, or of any particular State.
Thus, Congress has the authority to enact statutes that set forth the regulation of behaviors and other matters on military bases. In fact, it has done so. Members of the armed forces present on those bases must adhere to the Uniform Code of Military Justice as well as other federal laws that apply there. Civilians must comply with all federal laws applicable to the base.
In addition to statutes, the Department of Defense and a variety of other federal agencies may have regulatory authority on military bases and may have instituted rules that apply on those installations. Regulations may or may not include criminal penalties for violations, but whether they do or do not, compliance while on a military base is required.