It has been established that prison rape turns non-violent offenders into violent, vengeful rapists of women when they get out. Having been hurt and humiliated, they seek to reestablish their manhood by violently abusing someone else. Any minimal "deterrence" it offers is not worth the cost to society.
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.