How do mutations of viruses lead to drug resistance?
It doesn't. Viruses don't "know" anything. Mutations occur at random. Most of them don't do anything, or have a slight negative effect on the ability of the virus to infect and reproduce. However, there are billions and billions of viruses. Once in a while a random mutation will offer a significant advantage like immunity to an anti-viral drug. The viruses that have that beneficial mutation will then massively out-reproduce the viruses that don't have it. Eventually the population of viruses will consist mostly of individual viruses that have that mutation.