How does HIV mutate into other strains while keeping their virulent phenotype?
Others have already touched the important points. Consider this as a summary.


  What gives HIV the ability to mutate?


All organisms mutate by two mechanisms:


Replication errors
Mutagenesis by physical/chemical agents that cause a chemical change
(lesion) on DNA


The main enzyme responsible for HIV replication is reverse transcriptase which makes a DNA copy of its RNA genome. All RNA and DNA polymerases make some amount of error but the error rate of reverse transcriptase is much higher than usual DNA-dependent DNA polymerases because it does not have a proofreading mechanism. 


  How does a virus like HIV mutate into so many strains, and yet all of
  them are harmful to our immune system?


As indicated in previous answers, the mutations will produce a virions with a spectrum of infectivity/pathogenicity (some can even be non-infective).
However, the immune system acts as a selective barrier which selects only those mutants that can survive (similar to what happens in evolutionary process of natural selection). The selected strains expand their population and that is how these strains get established.