When it is contended on behalf of the defendant in any criminal prosecution that such defendant is at the time of the trial a person who is impaired by reason of mental retardation, a mentally ill person, an insane person, or a person of unsound mind, the court shall submit to the jury a proper form of verdict, and if the jury finds the defendant not guilty on account of such insanity, mental illness, or unsoundness of mind, they shall so state in their verdict, and the court shall thereupon order the defendant committed to the state hospital for the mentally ill, or other state institution provided for the care and treatment of cases such as the one before the court, until the sanity and soundness of mind of the defendant be judicially determined, and such person be discharged from the institution according to law.
Okla. Stat. tit. 22, § 925