If the purpose of imprisonment is to "teach them a lesson", obviously the lesson will be lost on the man who attacked somone because he genuinely believed they were an alien in human form. Seriously, are we setting an example to teach people not to allow them selves to become schizophrenic?
The hopelessly, dangerously insane have to be put away to prevent them from harming others. But there is no evidence that punishing the mentally ill makes them sane. But revenge is always politically popular, even if counterproductive.