Section 330(2) in The Code of Criminal Procedure, 1973
(2)If the case is one in which in the opinion of the Magistrate or Court, bail should not be taken, or if sufficient security is not given the Magistrate or Court, as the case may be, shall order the accused to be detained in safe custody in such place and manner as he or it may think fit, and shall report the action taken to the State Government :Provided that no order for the detention of the accused in a lunatice asylum shallbe made otherwise than in accordance with such rules the State Government may be have made under the Indian Lunacy Act, 1912 (4 of 1912).]]- 1. Whenever a person if found, under section 328 or Section 329, to be incapable of entering defence by reason of unsoundness of mind or mental retardation, 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 mental retardation 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.