The prison can't prevent such actions by prisoners, but when the prisoner's do such things, the administrators of the prison do need to take appropriate actions rather than just ignore the incidents.
How about a taser, aiming for the crotch. That would change their minds in a hurry.