There was a time when people often thought that mental illnesses and devil worship went hand in hand. It was once thought that women who cavort with the devil would go crazy and they were sometimes persecuted as witches. This is probably one of the origins of the mental illness sin theory and it has been regarded as true for many centuries. Since associating with an entity like the devil is indeed a sin, and people who cannot be easily diagnosed in the olden days for mental problems due to lack of certain facilities and knowledge regarding the human psyche, the mental illness sin theory seems to be the easiest way for people to explain away the behavior of the mentally disturbed.
The mental illness sin theory is also an easy way for people in the olden days to rationalize the sometimes unexplainable mental problems that some people in the community have. When a person suddenly rants and raves about something and does outrageous things due to mental problems, people would reason out that he or she is either possessed by a demon or is a practitioner of witchcraft that will be casting spells on them. Either way, it is viewed as a sign of either demon worship or witchcraft, and the person that is found guilty of this mental illness sin theory ends up either being hanged or being burned at the stake.
There are also religions today that believe in the mental illness sin theory and that the repercussions that a person who is sinful will receive from the Almighty One for being sinful will come in the form of mental anguish and torture that will make a person go crazy. There are people who misunderstand the mental problems that are suffered by some of their fellowmen and they sometimes conclude that the mental illness sin theory is the reason why a parishioner is exhibiting such outlandish or mentally unstable behavior. While committing a sinful act may cause a person to act differently because of guilt, the possibility of a person going crazy because of a sin that they committed is not exactly what you might call reality based thinking.
The reason why a person may act irrationally or may become unstable after committing a sin that he believes he may have to serve time for is usually due to the stress that the person gets from thinking of the repercussions that are in store for him. While there are those who do believe in the mental illness sin theory and that they will suffer from mental instability due to their infraction, there are also people in such religious communities who know of the mental illnesses that exist today, and they do not in any way associate it with sin or the punishments a person gets for sinning.