The innovation of moral thinking spread quickly because groups that developed it had a competitive advantage.
The initial incident established a new kind of thinking within the group that had accidentally discovered it. Within that group, the young males absorbed a new fact. "If you get caught masturbating, you will be beaten and killed." Even though the original incident was random, risk aversion by young males established the rule, and obedience to it, in the group. And as multiple groups either made this innovation independently or by inter-group learning, such groups out competed the groups that did not innovate.