Quick search by citation:

10 U.S. Code § 507 - Extension of enlistment for members needing medical care or hospitalization

An enlisted member of an armed force on active duty whose term of enlistment expires while he is suffering from disease or injury incident to service and not due to his misconduct, and who needs medical care or hospitalization, may be retained on active duty, with his consent, until he recovers to the extent that he is able to meet the physical requirements for reenlistment, or it is determined that recovery to that extent is impossible.
This section does not prevent the retention in service, without his consent, of an enlisted member of an armed force under section 972 of this title.