It's part of Title 10 USC, therefore it's federal law.
The restrictions are mandated by federal law Pub.L. 103-160 (10 U.S.C. § 654). The policy prohibits people who "demonstrate a propensity or intent to engage in homosexual acts" from serving in the armed forces of the United States, because their presence "would create an unacceptable risk to the high standards of morale, good order and discipline, and unit cohesion that are the essence of military capability." (10 U.S.C. § 654(b)) The act prohibits any homosexual or bisexual person from disclosing his or her sexual orientation or from speaking about any homosexual relationships, including marriages or other familial attributes, while serving in the United States armed forces. The act specifies that service members who disclose they are homosexual or engage in homosexual conduct shall be separated (discharged) except when a service member's conduct was "for the purpose of avoiding or terminating military service" or when it "would not be in the best interest of the armed forces" (10 U.S.C. § 654(e)).