This happens because the antibiotic kills off nonresistant bacteria, leaving the resistant bacteria with few competitors.
Bacteria become resistant to antibiotics through just two basic routes.
The first involves random, genetic mutations which occur readily in bacteria and sometimes produce a gene for a resistance trait or a gene that strengthens an already-existing resistance trait. The second route involves bacteria taking up resistance genes from other, nearby bacteria, a transfer that happens several ways. ONE bacteria inserts a long, narrow tube into another bacteria, then passes a plasmid to that bacteria through the tube. Another way that bacteria exchange resistance genes is when a virus called a bacteriophage infects a bacterium, picks up a resistance gene, then deposits it in another bacterium upon infection. The gross overuse and misuse of antibiotics is what has enabled bacteria to gain resistance to these drugs.