Civil commitment has a long history in this country, and carries a whole set of checks, balances, and judicial reviews with it. John Hinckley, who attempted to assassinate Reagan, is being held under such statutes. There are many others, as well.
The law recognizes the difference between criminal, insane, incompetent, and criminally insane conduct, and has for a long time. Sometimes it takes time to figure out just where a particular offender stands on that spectrum, and just how dangerous (or not) they really are.
Child pornography is a particularly thorny area, with current statutes being based on the idea that children used in the making of it are being abused. It's hard to argue against that in the case of individuals who are not sexually mature, but enters into a grey area, I think, when the subjects are sexually mature. It's even moreso when actual sex acts are performed by somebody legally defined as a criminal perpetrator. I've met young women who are 15 goin' on 30, for example, and I'm sure the same is true for young men, as well. Individual cases need to be judged on their merits, not on arbitrary templates applied often by whim... or bias wrt interracial or same sex acts. The case of Matthew Limon epitomizes this kind of irrational hatred, for example.