Section 335(2) in The Code of Criminal Procedure, 1973
(2)No order for the detention of the accused in a lunatic asylum shall be made under clause (a) of sub-section (1) otherwise than in accordance with such rules as the State Government may have made under the [Indian Lunacy Act, 1912 (4 of 1912)] [Now repealed by the Mental Health Act, 1987 (14 of 1987).].