There are a lot of mental illnesses that we have no cure for, yet we put these people in asylums (or at least we used to before the 80s). If someone is having these sorts of urges that they cannot control, they are not well. I think we should reserve jail for those who have a conscious choice over their actions and can be rehabilitated through punishment.
Also, there should be strict standards for due process on this sort of thing and it should never be a matter of the parole committee not knowing what to do with the inmate and resorting to this because of that.
Sex crimes aren't 'mental illness'
These people can still function as regular people. They can work, read, educate and care for their selves.
You might not know what a mental-ward is like, but usually those with real mental illnesses pose a repeated threat to their selves and others. They're closely monitored, checked in on and medicated as is necessary. Security is far more strict and so are protocols and measures taken. Contact with the outside is more limited and far more closely monitored.
A sex offender, if taken away from the temptation, isn't going to harm someone via their weakness. They simply, like a murderer or drug user, find it extremely hard to control their impulses and what they consider "needs." So, like a murderer or drug user, should be kept away from their problem as much as possible.
Thus, they'll do fine in the regular population. Those who are truly ill and need extensive care need to be in the mental-ward.
On top of the difference between the mentally ill and those who are just compulsive those in a mental-ward cost the state more money and are more demanding (legally and otherwise) to care for.
We need to limit the number of people in the mental ward so they don't become overrun with non-threats or with people without imbalances and the ones who do need and deserve that extra care, caution and treatment can still be treated ideally.
Now, if there still is an issue with the idea of having a sex-offender in with the regular population then perhaps what's really needed is a ward *just* for sex offenders - away from those who are mentally imbalanced and away from those who committed other vile crimes. There are different levels of offense and, therefore, there are different levels of imprisonment and care - so this last suggestion, I think, might be an ok solution.