I think this is one of those "received wisdom" things people say a lot but that, if you actually examine it, it doesn't add up beyond the most facile/superficial level.
Whilst D&D somewhat often (though perhaps not the majority of the time) features some Western-like elements, such as being set on a frontier/in a wilderness, and featuring characters who are "outside the law", it doesn't follow most of the patterns of the Western genre, which are extremely well-described here:
en.wikipedia.org
D&D is increasingly rarely about any of those things. Revenge/retribution? Rarely. Often rather it's pre-emptive. Honor codes? Almost never. I struggle to think of even a single adventure genuinely about that. Subjugating nature and/or natives? "Civilizing" the frontier? Errrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr it probably
shouldn't be, not in 2022, and you're saying lean into that? I suggest maybe don't lean into that! Just a thought!
Also the sheer rapaciousness of most D&D PCs, including in official adventures, where they're basically expected to steal everything not nailed down, does not jive at all well with being the protagonists in a Western (this includes Western-equivalents like Samurai movies), but rather tallies better with the antagonists/villains. You'll notice the plots also don't tally well, typically. The only major crossover which is common is the "outlaw gang" plot, which I think we all know is one of the least distinctive or specific elements of Westerns, and the most shared with other genres.
This only breaks down further as D&D characters gain levels, and become wildly superhuman in capabilities, something that fits extremely poorly with the Western genre.