No person having a mental illness or cognitive impairment so as to be incapable of understanding the proceedings or making a defense shall be tried, sentenced, or punished for any crime; but the person shall not be excused from criminal liability except upon proof that at the time of committing the alleged criminal act the person was laboring under such a defect of reason, from one of these causes, as not to know the nature of the act, or that it was wrong.