If icd and defibrillator can get infected, why put it in the first place? Is it really necessary for some people?

Yes. Any surgical incision can get infected. If your doctor recommends this procedure it is most likely necessary. The benefits outweigh the risks.
See answer. There are specific conditions for which an icd is implanted to decrease the risk of sudden death due to a cardiac rhythm disturbance. Infections are rare. The device can be life saving.