Section 16. (a) The court having jurisdiction over the criminal proceedings may order that a person who has been found incompetent to stand trial or not guilty by reason of mental illness or mental defect in such proceedings be hospitalized at a facility for a period of forty days for observation and examination; provided that, if the defendant is a male and if the court determines that the failure to retain him in strict security would create a likelihood of serious harm by reason of mental illness, or other mental defect, it may order such hospitalization at the Bridgewater state hospital; and provided, further, that the combined periods of hospitalization under the provisions of this section and paragraph (b) of section fifteen shall not exceed fifty days.
(b) During the period of observation of a person believed to be incompetent to stand trial or within sixty days after a person is found to be incompetent to stand trial or not guilty of any crime by reason of mental illness or other mental defect, the district attorney, the superintendent of a facility or the medical director of the Bridgewater state hospital may petition the court having jurisdiction of the criminal case for the commitment of the person to a facility or to the Bridgewater state hospital. However, the petition for the commitment of an untried defendant shall be heard only if the defendant is found incompetent to stand trial, or if the criminal charges are dismissed after commitment. If the court makes the findings required by paragraph (a) of section eight it shall order the person committed to a facility; if the court makes the findings required by paragraph (b) of section eight, it shall order the commitment of the person to the Bridgewater state hospital; otherwise the petition shall be dismissed and the person discharged. An order of commitment under the provisions of this paragraph shall be valid for six months. In the event a period of hospitalization under the provisions of paragraph (a) has expired, or in the event no such period of examination has been ordered, the court may order the temporary detention of such person in a jail, house of correction, facility or the Bridgewater state hospital until such time as the findings required by this paragraph are made or a determination is made that such findings cannot be made.
(c) After the expiration of a commitment under paragraph (b) of this section, a person may be committed for additional one year periods under the provisions of sections seven and eight of this chapter, but no untried defendant shall be so committed unless in addition to the findings required by sections seven and eight the court also finds said defendant is incompetent to stand trial. If the person is not found incompetent, the court shall notify the court with jurisdiction of the criminal charges, which court shall thereupon order the defendant returned to its custody for the resumption of criminal proceedings. All subsequent proceedings for the further commitment of a person committed under this section shall be in the court which has jurisdiction of the facility or hospital.
(d) The district attorney for the district within which the alleged crime or crimes occurred shall be notified of any hearing conducted for a person under the provisions of this section or any subsequent hearing for such person conducted under the provisions of this chapter relative to the commitment of the mentally ill and shall have the right to be heard at such hearings.
(e) Any person committed to a facility under the provisions of this section may be restricted in his movements to the buildings and grounds of the facility at which he is committed by the court which ordered the commitment. If such restrictions are ordered, they shall not be removed except with the approval of the court. If the superintendent seeks removal or modification of such restriction, the superintendent shall notify the district attorney who has or had jurisdiction of the relevant criminal case. If, after the superintendent communicates the superintendent's intention to remove or modify such restriction in writing to the court and the district attorney who has or had jurisdiction of the relevant criminal case, neither the court nor the district attorney makes written objection to such removal or modification within 14 days of receipt of the notice, such restriction shall be removed by the superintendent. If the superintendent or medical director of the Bridgewater state hospital intends to discharge a person committed under this section or at the end of a period of commitment intends not to petition for his further commitment, he shall notify the court and district attorney which have or had jurisdiction of the criminal case. Within thirty days of the receipt of such notice, the district attorney may petition for commitment under the provisions of paragraph (c). During such thirty day period, the person shall be held at the facility or hospital. This paragraph shall not apply to persons originally committed after a finding of incompetence to stand trial whose criminal charges have been dismissed.
(f) If a person is found incompetent to stand trial, the court shall send notice to the department of correction which shall compute the date of the expiration of the period of time equal to the time of imprisonment which the person would have had to serve prior to becoming eligible for parole if he had been convicted of the most serious crime with which he was charged in court and sentenced to the maximum sentence he could have received, if so convicted. For purposes of the computation of parole eligibility, the minimum sentence shall be regarded as one half of the maximum sentence potential sentence. Where applicable, the provisions of sections one hundred and twenty-nine, one hundred and twenty-nine A, one hundred and twenty-nine B, and one hundred and twenty-nine C of chapter one hundred and twenty-seven shall be applied to reduce such period of time. On the final date of such period, the court shall dismiss the criminal charges against such person, or the court in the interest of justice may dismiss the criminal charges against such person prior to the expiration of such period.