I think the problem lies in the fact that every person, even pedophiles or murderers etc, understands the need for a society to protect itself. If a person commits a crime, whether willingly or unwillingly (insane, can't control it, etc.), then society at least generally agrees they have to do something to keep this person from harming anyone else.
The problem is that sticking someone in jail where they could get abused "but we didn't cause it" is not a perfectly fitting punishment. Sticking them in jail or a hospital for an arbitrary amount of time decided by an arbitrary judge and jury (in US) is the best we can do.
I don't know the solution to those problems, but at the very least, something needs to be done to those who commit these crimes. It's too bad (and yet arguably good) that a child pornography crime can come down to a possibly innocent act as just having copy-able data on a hard drive (unless it's evidence of a physical crime by the person). It's definitely too bad that apparently the law is such that even obvious reasonable doubt (that some images weren't downloaded willingly) isn't taken as seriously, as it can still go to court, and e.g.: a jury of all moms with young daughters will still convict the guy in spite of the law.
Anyways, regardless of all that, even if we knew the exact reason why someone committed the crime, either consciously, subconsciously or due to a quirk, they are clearly a menace to society if they commit a heinous physical crime. It's just unfortunate that the solution is sometimes too extreme, too tame, or ineffective for many crimes.