I think they should attempt to establish order in prison and try to reduce rape but it does serve as a form of deterrance. If you don't want to do hard time, don't do the crime.
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.