The Code of Criminal Procedure, 1973 (CrPc)
330. Release of lunatic pending investigation or trial.
(1) Whenever a person is found, under section 328 or section 329, to be of unsound mind and incapable of making his defence, the Magistrate or court, as the case may be, whether the case is one in which bail may be taken or not, may release him on sufficient security being given that he shall be properly taken care of and shall be prevented from doing injury to himself or to any other person, and for his appearance when required before the Magistrate or court or such officer as the Magistrate or court appoints in this behalf.
(2) If the case is one 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 lunatic asylum shall be made otherwise than in accordance with such rules as the State Government may have made under the Indian Lunacy Act, 1912 (4 of 1912).