Mutations are random; the (pathogenic) bacteria (or any living being) will randomly acquire mutations that may be beneficial, deleterious or neutral to its fitness. Only beneficial and neutral mutations will survive the selection. Random mutations and survival of the fittest are not two independent mechanisms. The random mutations can alter the fitness as I mentioned and natural selection ensures the survival of the fittest.
Many pathogens have reduced genome (number of genes) compared to their free living relatives (Weinert and Welch, 2017). This is because they lack most of the genes required for synthesis of different metabolites required for survival. They rather obtain these metabolites from the host and hence they have the parasitic lifestyle. It is not possible for the pathogens to acquire that many genes to stop being pathogenic and become a free-living organism. It may be possible via lateral gene transfer wherein a bacteria may obtain an entire gene (or a set of genes) from another bacteria but the likelihood of that happening to convert a pathogenic bacteria to a non-pathogenic bacteria is negligible.
It is certainly possible that pathogens might lose the activity of some of the pathogenic genes (for example those required for toxin production) due to mutations. However, they may no longer be efficient pathogens and would be outgrown by the others who still retain those genes.