As with all things biological, it depends.
Some antibiotics, like rifampicin and chloramphenicol, readily give rise to spontaneous resistance mutations. These drugs target transcription and translation, respectively, and alterations of a single nucleotide in the bacterial genome can confer resistance. Since point mutations like these arise spontaneously at about one per million bacteria, there are always a few bacteria around that are resistant. If therapy is continued for long enough, they can proliferate to the point of being clinically significant in the course of treatment.
Some bacteria also tend to become spontaneously resistant at high rates. TB typically requires 6–9 months of antibiotic treatment, and this duration provides the means and the motive for resistant strains to emerge.
Gram-negative non-fermenters, most notoriously Pseudomonas, readily acquire mutations that increase expression of drug transporter proteins. The normal biological function of these proteins is to pump sugars, phosphates, oligosaccharides and metabolic intermediates in and out of cells, but they are non-specific enough that many antibiotics are also pumped out by them.
But most of the bugs that are labeled “superbugs” – MRSAs, CREs, VREs, ESBLs – acquired their resistance as fully developed systems on mobile genetic elements. These systems often include a set of regulatory elements, and worse, include a suite of resistance genes. Thus a plasmid that degrades penicillins might also confer resistance to several other antibiotics and environmental toxins such as disinfectants or metals.
The origin of these elements long predates medical use of antibiotics. Most antibiotics are natural compounds that have been produced by bacteria and fungi in the soil for hundreds of millions of years. Other bacteria have had plenty of time to develop a universe of resistance mechanisms – a “resistome”.
Medical overuse of antibiotics coupled with antibiotic use in livestock production provided a means for these resistance genes to migrate from harmless soil organisms to human pathogens. We can manage the proliferation of these genes through improved antibiotic stewardship, but they are never going away.
Some non paywalled reading: