Masturbation gets redundant. And a good chunk of prison sex that occurs isn't consensual. It's rape. Not only are the offenders getting their rocks off, rape is also a form of control. When they're in prison, they're in a controlled (to an extent) environment, meaning they're the ones being controlled. Rape puts them back in control, even if it's only for a short amount of time. And they don't care. Also, the prison guards don't care, they look the other way.