The restrictions are mandated by federal law Pub.L. 103-160 (10 U.S.C. § 654). They are law NOT just policy.
Here is the exact text, reprinted here for our mobile viewers!
Policy concerning homosexuality in the armed forces
(a) Findings.— Congress makes the following findings:
(1) Section 8 of article I of the Constitution of the United States commits exclusively to the Congress the powers to raise and support armies, provide and maintain a Navy, and make rules for the government and regulation of the land and naval forces.
(2) There is no constitutional right to serve in the armed forces.
(3) Pursuant to the powers conferred by section 8 of article I of the Constitution of the United States, it lies within the discretion of the Congress to establish qualifications for and conditions of service in the armed forces.
(4) The primary purpose of the armed forces is to prepare for and to prevail in combat should the need arise.
(5) The conduct of military operations requires members of the armed forces to make extraordinary sacrifices, including the ultimate sacrifice, in order to provide for the common defense.
(6) Success in combat requires military units that are characterized by high morale, good order and discipline, and unit cohesion.
(7) One of the most critical elements in combat capability is unit cohesion, that is, the bonds of trust among individual service members that make the combat effectiveness of a military unit greater than the sum of the combat effectiveness of the individual unit members.
(8) Military life is fundamentally different from civilian life in that—
(A) the extraordinary responsibilities of the armed forces, the unique conditions of military service, and the critical role of unit cohesion, require that the military community, while subject to civilian control, exist as a specialized society; and
(B) the military society is characterized by its own laws, rules, customs, and traditions, including numerous restrictions on personal behavior, that would not be acceptable in civilian society.
(9) The standards of conduct for members of the armed forces regulate a member’s life for 24 hours each day beginning at the moment the member enters military status and not ending until that person is discharged or otherwise separated from the armed forces.
(10) Those standards of conduct, including the Uniform Code of Military Justice, apply to a member of the armed forces at all times that the member has a military status, whether the member is on base or off base, and whether the member is on duty or off duty.
(11) The pervasive application of the standards of conduct is necessary because members of the armed forces must be ready at all times for worldwide deployment to a combat environment.
(12) The worldwide deployment of United States military forces, the international responsibilities of the United States, and the potential for involvement of the armed forces in actual combat routinely make it necessary for members of the armed forces involuntarily to accept living conditions and working conditions that are often spartan, primitive, and characterized by forced intimacy with little or no privacy.
(13) The prohibition against homosexual conduct is a longstanding element of military law that continues to be necessary in the unique circumstances of military service.
(14) The armed forces must maintain personnel policies that exclude persons whose presence in the armed forces would create an unacceptable risk to the armed forces’ high standards of morale, good order and discipline, and unit cohesion that are the essence of military capability.
(15) The presence in the armed forces of persons who demonstrate a propensity or intent to engage in homosexual acts 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.
(b) Policy.— A member of the armed forces shall be separated from the armed forces under regulations prescribed by the Secretary of Defense if one or more of the following findings is made and approved in accordance with procedures set forth in such regulations:
(1) That the member has engaged in, attempted to engage in, or solicited another to engage in a homosexual act or acts unless there are further findings, made and approved in accordance with procedures set forth in such regulations, that the member has demonstrated that—
(A) such conduct is a departure from the member’s usual and customary behavior;
(B) such conduct, under all the circumstances, is unlikely to recur;
(C) such conduct was not accomplished by use of force, coercion, or intimidation;
(D) under the particular circumstances of the case, the member’s continued presence in the armed forces is consistent with the interests of the armed forces in proper discipline, good order, and morale; and
(E) the member does not have a propensity or intent to engage in homosexual acts.
(2) That the member has stated that he or she is a homosexual or bisexual, or words to that effect, unless there is a further finding, made and approved in accordance with procedures set forth in the regulations, that the member has demonstrated that he or she is not a person who engages in, attempts to engage in, has a propensity to engage in, or intends to engage in homosexual acts.
(3) That the member has married or attempted to marry a person known to be of the same biological sex.
(c) Entry Standards and Documents.—
(1) The Secretary of Defense shall ensure that the standards for enlistment and appointment of members of the armed forces reflect the policies set forth in subsection (b).
(2) The documents used to effectuate the enlistment or appointment of a person as a member of the armed forces shall set forth the provisions of subsection (b).
(d) Required Briefings.— The briefings that members of the armed forces receive upon entry into the armed forces and periodically thereafter under section 937 of this title (article 137 of the Uniform Code of Military Justice) shall include a detailed explanation of the applicable laws and regulations governing sexual conduct by members of the armed forces, including the policies prescribed under subsection (b).
(e) Rule of Construction.— Nothing in subsection (b) shall be construed to require that a member of the armed forces be processed for separation from the armed forces when a determination is made in accordance with regulations prescribed by the Secretary of Defense that—
(1) the member engaged in conduct or made statements for the purpose of avoiding or terminating military service; and
(2) separation of the member would not be in the best interest of the armed forces.
(f) Definitions.— In this section:
(1) The term “homosexual” means a person, regardless of sex, who engages in, attempts to engage in, has a propensity to engage in, or intends to engage in homosexual acts, and includes the terms “gay” and “lesbian”.
(2) The term “bisexual” means a person who engages in, attempts to engage in, has a propensity to engage in, or intends to engage in homosexual and heterosexual acts.
(3) The term “homosexual act” means—
(A) any bodily contact, actively undertaken or passively permitted, between members of the same sex for the purpose of satisfying sexual desires; and
(B) any bodily contact which a reasonable person would understand to demonstrate a propensity or intent to engage in an act described in subparagraph (A).