If radiation causes cancer, how can it be used to treat cancer?

It's complicated . Low levels of radiation can change the dna in normal cells that 10 to 30 years later can turn into cancer. With cancer higher doses of radiation kills the cells while normal cells recover. The probability of killing cancers is far higher than the probability that the normal cells become cancerous. The chance of getting radiation cancer is low and it takes a long time to happen.
Complicated. Actually, after treatment with radiation.. There is a long term risk of developing sarcomas (low risk but real). Acute radiation treatments for cancer work by disrupting the dna of rapidly reproducing cancer cells. The cancer cells can't fix the damaged dna and subsequently die. There is a risk of later developing secondary cancers but lower than the curren real risk of the cancer being treated.