Evolutionary history predicts the stability of cooperation in microbial communities