Two points:
1. we should try to reduce prison rape for the reasons you stated and for humane reasons
2. but it does serve a useful purpose as a deterrance. Fear of rape is probably the number one fear someone has of going to prison.
No prisoners should be enjoying sex with each other including the thug rapists. Some of them get more sex in prison than without. What kind of deterrance is that?