(a) Whenever a person is hospitalized or receives evaluation or treatment services under this chapter in connection with a criminal charge or conviction, wherever incarcerated, the person shall receive credit toward the satisfaction of the sentence for the time spent in the custody of the commissioner.
(b) When a person has been transferred from the department of correction to the custody of the commissioner, the person shall be released from the custody of the commissioner at the expiration of the sentence unless a judicial hospitalization order has been entered with respect to the person.