The insanity or Mental Disease or Defect defense is raised when a person charged with a crime lacked criminal responsibility at the time of the crime because they lacked substantial capacity to know or appreciate either:
The nature or consequences of the conduct; or
That the conduct was wrong.
Mental disease or defect is an affirmative defense and can be established by expert medical (psychiatric/psychological) testimony, prior mental health related hospitalizations, medical records, and/or the nature, circumstances, and facts of the crime.
This is different than being mentally fit to proceed in the case against you. This defense cares about your mental state at the time of the crime, not at the time of the charges, proceedings, or trial.