Actually it all comes about when we fail to complete certain doses of medication prescribed by doctors, for example, I have typhoid and I am given medication to help kill that bacteria I take half a dose and decide that I'm okay and the other half I discard it what happens is that the ”partially” killed bacteria now recognizes the drug I am using and adapts itself and its offspring to be resistant to that drug
Hence it is actually because of uncompleted medication