Long-term social dynamics drive loss of function in pathogenic bacteria