When a human reaches puberty, his ‘Aql, or sense of discernment between right and wrong, is considered to have reached the stage where he becomes accountable for his every conscious action. He becomes responsible to seek a relationship with God through prayer and righteous living, and is held accountable and penalised for his transgressions. He must perform all obligatory Islamic rituals, and avoid all prohibitions.
Of course, this is according to age and stage, and it increases and develops with time and experience. On the other hand, one who is insane, hasn't, and maybe never reaches this stage, and thus he can not be held accountable or liable for his actions.