I'm not sure such a law is realistic. First of all, public fapping is already illegal in most, if not all jurisdictions. It's called public indecency.
Otherwise, an unenforceable law is not worth the paper it's written on. If someone faps in their bed-sheets at 4:00 am in the morning because they can't sleep then how do you expect the state to enforce something like that? Are they going to start putting cameras in everyone' bedroom? Violate privacy laws by using people's smartphones to monitor them? Have mandatory urine tests/testosterone tests?
You need to have a 1984-Big Brother like totalitarian government, where all the citizens are slaves, before a law like that can be even enforceable.