Different public spaces have wildly different expectations with regard to social interaction.

Most people know better than to strike up a conversation with a stranger who is watching a theater performance, reading in a library, or walking briskly to work. Whereas chatting with people at a club, sporting event, carnival, conference, convention, etc is socially acceptable.

But many places are ambiguous like public transit, gyms, shops, airplanes, etc. Assessing whether someone in those contexts would welcome interaction with strangers requires social awareness.

Unfortunately, some people overlook or deliberately ignore these cues, so folks who aren't interested in social interaction have taken to wearing headphones in those contexts to make it as obvious as possible. If you're the kind of person who is surprised by how many people are now wearing headphones, it may be because you were missing their more subtle cues before.