Where the person named in the petition for commitment is a resident, patient, or inmate of a state institution, the court may commit the person to the care and custody of the Department of Health and Human Services. The department may, in its discretion, detain the resident, patient, or inmate in the institution in which he or she is a resident, patient, or inmate at the time of the hearing, subject to the rules of that institution, or may transfer him or her to the Beatrice State Developmental Center.