(1) Whenever a person if found under section 367 or section 368 to be incapable of entering defence by reason of unsoundness of mind or intellectual disability, the Magistrate or Court, as the case may be, shall, whether the case is one in which bail may be taken or not, order release of such person on bail:
Provided that the accused is suffering from unsoundness of mind or intellectual disability which does not mandate in-patient treatment and a friend or relative undertakes to obtain regular out-patient psychiatric treatment from the nearest medical facility and to prevent from doing injury to himself or to any other person.
(2) If the case is one in which, in the opinion of the Magistrate or Court, as the case may be, bail cannot be granted or if an appropriate undertaking is not given, he or it shall order the accused to be kept in such a place where regular psychiatric treatment can be provided, and shall report the action taken to the State Government:
Provided that no order for the detention of the accused in a public mental health establishment shall be made otherwise than in accordance with such rules as the State Government may have made under the Mental Healthcare Act, 2017.
(3) Whenever a person is found under section 367 or section 368 to be incapable of entering defence by reason of unsoundness of mind or intellectual disability, the Magistrate or Court, as the case may be, shall keeping in view the nature of the act committed and the extent of unsoundness of mind or intellectual disability, further determine if the release of the accused can be ordered:
Provided that—
(a) if on the basis of medical opinion or opinion of a specialist, the Magistrate or Court, as the case may be, decide to order discharge of the accused, as provided under section 367 or section 368, such release may be ordered, if sufficient security is given that the accused shall be prevented from doing injury to himself or to any other person;
(b) if the Magistrate or Court, as the case may be, is of the opinion that discharge of the accused cannot be ordered, the transfer of the accused to a residential facility for persons with unsoundness of mind or intellectual disability may be ordered wherein the accused may be provided care and appropriate education and training.