The rule originated back in the old, moralistic system of corrections, in the days when they were still “penetentiaries” back when masturbation was still thought of as sort of perverted and shameful.
Today, the rule’s application enables the staff to punish those offenders who purposefully masturbate where everyone can see them, or use it to offend the female guards. (Imagine being a female guard with an inmate sitting near you beating off, grinning at you and making lacivious comments, and unable to do anything about it.)
There are also inmates who, uhm, masturbate in unusual ways, and can hurt themselves. (There was one inmate who had to be rushed to the hospital because the broom handle he was using to pleasure himself got stuck.) You also have your auto-erotic asphixiatiors and the like. Those people can then be put into special control where they will be unable to harm themselves.
Everyone understands, of course, that men need some sort of sexual outlet. That’s why if a guard does a surprise bunk inspection and finds a man was fondling his naughty bits beneath the covers, he just ignores it.
Certain types of pornography are also allowed. “Playboy” is permitted, but anything that shows penetration, bondage/dominance/rape fantasy, or images desgned to appeal to those who fancy young children are not. Believe it or not, there are people assigned to porn review, to make sure that everything sent in to the inmates is permissable.
Movies and television shows are given the same scrutiny. My husband is in charge of this-- I’ve teased him that part of his job is watching TV. The inmates get the network channels, but if something on the networks is considered particularly aggregious (such as a show featuring torture) they block it.
The inmates are shown movies, which are selected from a list provided by a company who specializes in this sort of thing. Hubby watches the movies to make sure they’re okay before broadcast. “Hostel” will never be shown in the prison, for example, but the inmates will probably get to see the next “X-Men” movie when it’s released to the company. Anything with graphic sex scenes, or rape, sadmism, underage kids in sexual context will not be shown.