The Church teaches, dogmatically, that certain conditions remove man's ability to freely choose:
1. Young age.
Infants, for example, act on impulse, instinct, and bodily need, not on intellect. Past infancy, the child still cannot reason well (distinguish between right and wrong and decided between them) until about age 7, which is why that's the traditional age for receipt of Holy Communion.
2. Severe mental impairment.
That would include dementia, any brain damage in an adult which similarly affects will. Once a person loses the ability to control impulses, he loses the ability to sin, despite the evil/sadness, etc. he may inflict on others due to his actions.
3. Coercion from another person.
With regard to #2, psychosis is a little more complicated, so I don't want to go into it here in great detail. I will say this, however, with regard to mental disturbance, because it came up in another thread, too: A person who knows or senses that something is amiss in his or her psyche, and becomes aware of evil consequences that have resulted because of his own disturbed psyche (whether neurosis, mood disorder, or psychosis) has an affirmative obligation to seek healing, which is normally through secular means (professional mental health treatment). That would be a universal moral requirement, not limited to Catholics. It's just part of natural law. So the sin would be in -- having become conscious at any point of the evil effects of an internal condition -- choosing not to do anything about that, for any reason.
The second important point about #2 is that any mental disturbance, untreated, is wonderful soil for the devil. By definition, mental impairment is a disorder of a primary kind. Mental impairment weakens the resolve of the person affected, distracts him, reorganizes his priorities toward feeding his illness rather than cooperating with the order of the universe and his humble place within it. True health is not the immediate object of desire; rather, immediate gratification is -- gratification in the form of satisfying a deluded sense of self, acquiring power in minor or major ways in order to fulfill a distorted grandiosity, etc.
The important point about all of this, for purposes of the thread conversation, is that only certain situations release a human being from responsibility for decisions to sin. Most of us will not be in category 2 or 3 for most of our lives. And merely having a mental condition is not in itself a sin; most of these are genetic, even if the triggers for them come much after birth.
The devil is an opportunist; this is also Catholic dogma. He seeks, actively, for his opportunities to invade, seize, and destroy, and mental and spiritual disorders are fertile ground for him. I recommend Fr. Ripperger's many audio sermons on Spiritual Warfare. He is an exorcist who explains some of the conditions which "invite" (even passively) the entrance of the devil. Fr. R is also very clear, however, that --as other posters have said -- the devil cannot remove our will; we give him permission one way or another -- through weakness, acquiescence, etc. Fr. R also says that he has never encountered a possession of a person who was living a normally holy life (lay life, not consecrated life), keeping up their prayer activity on a regular -- not extreme-- basis and who was staying out of mortal sin.
Entrenched sin or unconfessed sin is a ripe opportunity for the devil. Ingrained evil habits, also. Habits, by the way -- despite the modernistic acceptance of the term "addiction" to describe every stubborn habit -- do not remove our free will. That includes pornography use. A person may weaken his or her resolve against a sinful habit, due to augmented levels of expectation, but the culpability remains. The more persistent any of our sins are, the more obliged we are to root them out; at no point does persistent sin remove our free will.