im guessing you all asume that penicilin was the first antibiotic that bacteria have ever encounterd to name a few natural antibiotics
garlic, honey, Carob powder, Aloe Vera, Grapefruit seed extract, ....
all bacteria have had ample time in human history to develope a resistance to these natural antibiotics, that resistence could have helped them to evolve a resistance to industrial antibiotics.
in short they did not haveto invent a way to defend themselves from a totaly new substance they only hadto invent a way to defend themselves from a more powerful substance that kills them.