The evolution of communal behaviour beyond that driven by survival (e.g., simple mating heuristics, common shelter, or climate) and convenience (i.e., common food source) correlates with two major advents in the development of animal physiology.
First, neuroendocrine physiology evolved in early vertebrates to include homologs for testosterone and oxytocin pathways, and other neurotransmitters throughout the central nervous system, including within organs. These neuropeptides have been found to promote behaviours associated with justice/punishment, loyalty, and other basic forms of morality also evident in other species with homologs for these neurophysiologies.
Second, the development of the prefrontal cortex in mammals provided for temporal logic through associative behaviour. These biochemical associations—like those evident in post traumatic stress disorders—allow for temporal thinking wherein the consequences of a decision are considered. This further informs moral judgements (i.e., if a behaviour is permitted in a group and allowed to continue, it's long-term results are also considered in a decision whether it should or should not be suppressed by the group.)
By relying on a communal reference group to inform decision-making, more complex variations of morality emerge. "Diffusion of responsibility" is an example of this, wherein individuals are less likely to take action based on the number of parties present. The function of this behaviour is necessary—as in the tale of "The Boy Who Cried Wolf"—to collectively evaluate threats as a group, avoiding "false alarms" and thereby conserving energy. Collective/normative morality has the added effect of increasing the survivability of larger communities, thereby further perpetuating communal behaviour. To some extent the decision-making processes in these communal reference groups is still influenced by more primitive social hierarchies, i.e., dominant member of the group are referred to first by other members.
In conclusion, morality must be more clearly defined and categorized to identify correlating changes in primate physiology throughout our evolution. Early communal behaviour—loyalty and justice (punishment)—may be driven by the interactions of a few neuropeptides whereas more complex social norms (e.g., selective enforcement of capital punishment) are based on associative thinking and communal reference groups.