The provisions of § 17a-510 shall apply to any person committed to such hospital pursuant to sections 17a-514 and 17a-515, except that upon such discharge (1) the person shall be returned to any such institution administered by the Department of Correction as the Commissioner of Correction shall designate, unless his custody in the Commissioner of Correction has terminated and (2) the Commissioner of Correction shall notify the prosecuting official of any court in which any such person has criminal charges pending against him.