When someone occasionally engages, I extremely quickly dismiss them in the most polite, but firm, way possible. I also intentionally keep a demeanor that generally signals I’m not open to random conversations (I avoid eye contact etc.), but that often doesn’t work. At the gym it is particularly problematic, I’m focusing on gathering strength for my next set and sometimes people bother you even if I am wearing headphones.
I truly do not have a problem with who I am, I’m comfortable in my shoes.
As such, never in a million years I would approach a stranger to strike up a conversation, it would seem an incredibly rude thing to do towards them, on top of clearly not having any desire to engage from my side.
I’ll talk for hours straight to my wife, close family and the very few friends I have though!
And I think that's the answer; people who don't want to talk will simply tell you! And everyone carries on.
It's one thing to not want it and to be comfortable not wanting it, but viewing it as rude goes way beyond that and is not rational.