That's the thing.
There is not perfect solution. There is no end to this, because fantasy and other fictional works will always be tainted by our internal biases, and many of our internal biases are based off of racism, ableism, sexism, anti-LGBTQ+ bigotry, and other types of bigotry. No one is asking for future writers to be perfect or keep their internal biases away from fantasy, because, frankly, that's impossible to do. Perfection is the enemy of progress.
We will never get rid of every problematic part of D&D, because humans cannot be perfect. However, that isn't an argument against progress, it's one for it. If we aren't vigilant and meticulously scrutinizing D&D products, we're willfully ignorant of the stereotypes that may be perpetuated by the products.
And the answer is different for every scenario. Some of the time, it's better to just abandon the setting if it has so many problems built into its core (Mystara probably falls into this category, and I would even argue that certain parts of the Forgotten Realms do, like Maztica). Sometimes it's better to just ignore that part of a setting when republishing it (like Van Richten's Guide to Ravenloft abandoning the Caliban) and publish the product with no mention to it. A lot of the time it's fine to just make minute changes to how certain parts of the product, typically by just removing language or even artwork that is problematic (how the Vistani are described in various Ravenloft products, how the Chultans are described in Tomb of Annihilation, etc). Sometimes you have to retcon something out of existence and replace it with something else (Hexblood kind-of replace Caliban in Ravenloft, but not really). The solution depends on the context. There is no perfect "one-size-fits-all" solution here. Sensitivity readers and cultural consultants are probably needed to fix most of these issues, and even they won't perfectly fix the problem (because nothing will).
A lot of the time, I would be fine with just straight-up ignoring some parts of past settings that could get translated to D&D 5e if they're not that big of a part of the setting (Caliban from Ravenloft, Gully Dwarves from Dragonlance). Sometimes they're such a big part of the setting that it might be better fully abandoning the setting or completely replacing that part of the setting with something entirely different. Sometimes it's fine to keep that part of the setting, but still dialing back the problematic parts of it (I'd probably argue that most of the issues with certain cultures/races in Eberron and Exandria could fairly easily do this).
Context is everything. The answer depends on the context. I don't know what answer you wanted, but I hope this one suffices.