It completely depends on the mental illness for a start, some may play a part whilst others do not.
As someone mentioned above, it is not an excuse but can be a reason for why people do such things.
Also, it depends on what you mean by mental illness really. Really, you could say that every single murderer/serial killer/rapist/paedophile etc has something mentally wrong. Whether they have a diagnosis from something like DSM-IV-TR is another thing.
Plus it is always the thing of, why do the majority of people without such mental illnesses not go on to commit that crime. There are many reasons, so in my opinion, it is definitely not an excuse but can be a causal factor for some