The question's moot if you consider the issue of capital punishment -- if there's no capital punishment, the issue of sanity regarding its implementation becomes irrelevant. If there's some who insist on such a penalty, then there's a huge implementation issue, if not outright reverse discrimination -- a sane individual commits a serious crime, and can incur the penalty; an insane individual commits the same serious crime and does not. If we adhere to the Rule of Law, then the consequences of actions are equally applied to all who are found guilty.
I think that there is something very wrong with the state putting to death someone who has a validated case of mental illness. I think that it speaks poorly to any state or community that would do this. In my mind, it is not that people with mental illness should escape punishment, but treatment has to be a part of the meted out sense of justice and not straight execution. I think that someone who has a mental illness is not entirely in full and sound mind to understand the implications of what has been done, which is why execution in my mind seems to not be an appropriate measure in achieving justice. It is extremely complex, and no perfect solution might be present, but I believe that to ensure that treatment and not execution is of vital importance.
Mental illness covers a wide variety of disorders and diseases, so it's hard to say. Schizophrenia, for example, causes people to be divorced from reality, to hallucinate, sometimes become paranoid. It's hard for me to justify in my mind how such a person should pay with their life because they have a disease.
On the other hand, there are many mental conditions and illnesses where the person is fully aware of actions and consequences. So I don't think there is a blanket, once-size-fits-all approach to this issue, and I'd leave it in the hands of judges to decide on a case by case basis.
It depends, in my mind, on the severity of the mental illness.
I am not sure I approve of capital punishment at all, but I am really sure that it could only be appropriate if a person knowingly did wrong. If a person is really so mentally ill that they cannot tell right from wrong, they clearly should not be punished for their actions. However, if they are mentally ill BUT able to know right from wrong, they should be punished.
This problem is one reason why I think that capital punishment has serious problems. It is very hard to tell which people are mentally ill enough to deserve punishment and which are not.