The Original Series straight-up used the Downtown Mayberry set from The Andy Griffith Show twice.
Star Trek used a LOT of stuff from other properties due to money. But I still feel like the western sets were used by choice. Especially in Enterprise, which was meta at that point.
To be fair, I’d say cowboy appearances would be relatively proportional to the population, maybe 1 or 2% of each series…
Except DS9, which has a bit of an Alamo obsession.
Maybe not literally, but the season 3 episode where Discovery arrived in the future went hard on the western vibes. I think they even included swinging saloon doors at one point.
In case of TOS, they literally pitched it as a kind of Western but in space to the studios due to the popularity of the genre on TV (both DeForest Kelly and Shatner had also already appeared in Western serials).