First keep in mind Prison and Jails are different place.This is important for a few reasons, we'll get to later.
Jails (Commonly refered to in much of the rest of the world as "Gaol"), as short term holding facilities offer far less services, have a higher turn over and in a lot of ways are much more dangerous places than Prisons. Jails are often processing centers, where they discover all sorts of things: whether an offender has had previous contact with the system, drug usage, medical conditions, religious preferences, dietary preferences, sexual preferences and or proclivities, gang involvement, educational levels, and much, much more.
All of this is documented, but not always accurately-some Jails are run by Cities or Counties who are having financial difficulties, others simply aren't prepared to deal with a certain level of offender. Some offenders also lie about a variety of things-from Gang Involvement, to Sexual preferences to Medical Conditions-for a variety of reasons.
Prisons are long term holding facilities. Many cite rehabilitation as a goal, however that's a rather recent development. Most American's forget that Prisons were originally called Penitentiary's. As in "Penitent", or a place to "regret" or "feel regret for sins or offenses". Most of the American Prison system was originally set up by the Quakers. Why do I bring this up? Well what is Rehabilitation? Is it when you never commit another crime? Is it when you function in society like everyone else? Well how do you codify that? What's an accurate measurement or standard?
While we know some of the factors that contribute to a person being incarcerated, the facts are there is no hard rule as to who will end up locked up.
So if Rehabilitation isn't a quantifiable element then you have to, as someone running a prison, figure out what is. What can you control? Staff safety, to a point. Programs, to a point. What resources you have available-most people hate to spend money on Jails and Prisons. In many of the largest states we spend more on Prisons and Jails than we do on schools and roads. Obviously that's not easy for everyone to swallow.
So many Prisons are trying to rehabilitate on a budget. This means many vital programs are vastly underfunded, understaffed, and to top it off many times there's not always enough programs to meet needs. Add in people hustling to get into programs to victimize people (For instance Homosexual Predators will try to get into GED programs with younger, more vulnerable convicts.), People refusing to cooperate with program. (You don't need a GED to sling dope. And McDonalds doesn't pay 3k a week.)
In the American prison system, and I think what I've read about Prison's globally Rape is far less about sex, and way more (Like 3278 mentioned) is about Power. Often Rape is about punishing people, or empowering people. (Mostly the Rapist, but often Gangs will use Predators to collect debts, punish violations, or to humiliate opponents.)
In my honest opinion Prison Homosexuals are a different breed than actual Homosexual in the world. Sex is less about love, and more about building alliances, dominance, buying or selling (Drugs or Store Goods), and power. Prison is a hierarchical society. There is, despite the best efforts of the authorities a "Head" (Leader) Black, White, and Hispanic convict. (In areas where other significant minorities congregate you'll get others as well, but those are the big three.) These convicts run things at their prisons, and report to other convicts who run things at other prisons, and even some who run things state wide. The real mess in this comes as Gangs are formed, and then exit prison and continue their activities. Soon the lines blur.
I suggest anyone who'd like to know more see shows like
Gangland, and
Lockdown. They do a great job of exploring the ins and outs of this stuff. Feel free to ask me questions if you'd like-this was way more cathartic than I thought it would be.