I guess you could boil it down to the myth of the rugged individual facing a vast, indifferent land. But honestly, I keep going back to the ambivalence these characters carry. They're not knights; they're more like walking contradictions. A guy like the marshal in 'Shane' or the worn-out rancher in 'Lonesome Dove' embodies a code, sure—honor among thieves, a handshake deal, protecting the weak—but it's a code born from sheer necessity, not some chivalric ideal. The frontier strips everything else away. What's left is just a person and their capacity for violence or mercy, and usually a heavy dose of both.
What really defines them for me, though, is that sense of being anachronistic even in their own time. The railroad is coming, the wire fence is going up, and the world is getting smaller and more lawful. The classic gunslinger, the true frontier archetype, knows his era is ending. That's where the tragedy—or the romance, depending on the book—comes from. He's fighting not just outlaws or nature, but the future itself. His skill with a Colt is his entire identity, and when society no longer has a place for that, what is he? That's the quiet question haunting so many of these stories, way more than any shootout.