Quick search by citation:

10 U.S. Code § 1169 - Regular enlisted members: limitations on discharge

No regular enlisted member of an armed force may be discharged before his term of service expires, except—
(1)
as prescribed by the Secretary concerned;
(2)
by sentence of a general or special court martial; or
(3)
as otherwise provided by law.