Dynamics of Moral Behavior in Heterogeneous Populations of Learning Agents