That's not why coal tar works.
Coal tar is technically carcinogenic, yes, but no study has found any association with cancer when used topically in low doses [1].
Coal tar's mechanism of action is thought to be carbazole, an aryl hydrocarbon. It is assumed to work through binding to the aryl hydrocarbon receptor, a relatively newly discovered immune cell regulator. Tapinarof (Vtama) is a new medication that also works on ArH and is really effective at reducing inflammation.
Coal tar was also used together with UVA light and psoralen (a light-sensitizing medication) to treat skin diseases like psoriasis, a protocol called Goeckerman therapy that's no longer commonly practiced. This combination does carry the risk of cancer, but it's probably due to the UVA and not the coal tar.
[1] https://www.sciencedirect.com/science/article/pii/S0022202X1...