The basic distinctions are:
Not guilty by reason of insanity: A defendant is found not guilty because they were insane at the time of the crime and, therefore, lacked the intent required to perform a criminal act (known as mens rea). The defendant either did not know what they were doing was wrong or, if they knew that the act was wrong, they could not control their actions.
Guilty but mentally ill: This verdict allows juries to find mentally ill defendants criminally liable. Defendants found guilty but mentally ill either receive psychiatric treatment while in prison or are placed in a mental hospital. In the latter case, when they are well enough to leave the hospital, defendants will be transferred to prison to serve the remainder of their sentences.
Competent to stand trial: A defendant understands the nature of the proceedings against them and is able to assist their lawyer in their defense. All state courts and federal courts require that a criminal defendant be competent to stand trial.