22. Nothing is an offence which is done by a person who, at the time of doing it, by reason of unsoundness of mind, is incapable of knowing the nature of the act, or that he is doing what is either wrong or contrary to law.
Bharatiya Nyaya Sanhita, 2023
Section 22: Act of a person of unsound mind
Chapter III — General Exceptions
Source: official text of the Bharatiya Nyaya Sanhita, 2023 (Ministry of Home Affairs).