Nothing is an offence which is done by a person who, at the time of doing it, by reason of mental illness, is incapable of knowing the nature of the act, or that he is doing what is either wrong or contrary to law.
Law reference / Bharatiya Nyaya Sanhita, 2023 / Chapter III
Section 22. Act of a person of mental illness
GENERAL EXCEPTIONS
Please note: this text is the Bharatiya Nyaya Sanhita Bill, 2023 (Bill No. 121 of 2023, as introduced in the Lok Sabha). Parliament later passed a revised version as Act No. 45 of 2023, which is the law in force from 1 July 2024. Many section numbers differ (for example, murder is clause 101 here but section 103 in the Act), so use the IPC ↔ BNS table for the numbers of the Act and check the official text on India Code before quoting a section.