Most people consciously think they would prefer to associate with people they "identify" with. In real life you don't have much in the way of signaling so this process was not especially efficient. And that was a great thing. It meant people who had completely different worldviews would end up becoming friends, and having some fun if not heated debates at times. And most importantly they also kept each other tethered to reality. Enter social media. Now, no matter how extreme a group you "identify" with, you can find millions of people fitting that. And people utilize this to filter people down to just these people.
But this filtering now tends to drive divisiveness in two big ways. The first is that as people lose contact with those they do not "identify" with, it creates a dehumanization. The other issue is the even bigger one, and also contributes heavily to the first -- people lose touch with reality. Imagine the answer to a problem is 0. You have one group that insists it's at least 20, and another that insists it's at most -20. Now all the 20+ guys join together. And now thinking it's 25 is really kind of moderate - literally nobody thinks it's less than 20 and lots of people even think it might be in the 30s, or higher! Their collective starts going further and further up. Next thing you know the average is 30, then 40, then ... And vice versa for the other group. This likely a similar process to how you get from 'dress modestly' to 'wear opaque black sacks that cover everything including the eyes.' It's a homogeneous collective raging on in who can be more virtuous (by the standards of the collective) without any sort of counter-balancing force going "I LOVE BIKINIS! Live free and natural. Nude beaches are what we need!"
But the key point of this all is that this filtering would be impossible without social media. I completely agree that the media is contributing heavily to this, as well as politicians, especially those who play into identity politics. But on the other hand, I think their behavior is arguably more of an effect than a cause. In a divided world, the way you make money with things such as media is not by walking the line, it's by jumping off the deep end one way or the other. And similarly for politicians. People actually get angry when people in any way work with "the other side." Consider the outrage that Musk would dare work on a presidential advisory board where he would actually have a voice that'd go straight to the president.
I would add one thing, though... in the days before social media, but also before near-instant transportation and tv and stuff, people lived in geographically isolated communities. While there wasn't cultural self-selection, your culture was selected for you, and almost everyone you knew was like you.
This is reflected in politics as well. Urban areas are necessarily more socially diverse than rural areas. If you live in a big city, you rub elbows with people different from you every day. You learn to be tolerant and respectful of social diversity just for your own sanity. Homogeneous rural communities don't learn tolerance, because they don't need it, and it's arguably a hindrance. So we wind up with socially tolerant, diverse liberals, and socially intolerant, monoculture conservatives (not passing a judgment here). It's a result, not a cause.
Social media exacerbates both these tendencies... on one hand, it's so easy to build purist echo chambers, which lead to holier than thou political one-upmanship and drive extremist views. On the other hand, we're constantly exposed to people wildly different to us through friends-of-friends. That's a lot of cognitive dissonance. Rather than leading to more tolerance, it's leading to uglier forms of intolerance.