If I found myself sitting next someone, whether on public transport or at a coffee shop/cafe/restaurant that just couldn’t shut the fuck up, I would get up and find somewhere else to sit if possible. Otherwise, I’d just sit there and ignore them. I don’t enjoy talking to strangers or being talked to by strangers for that matter, so I would put in some headphones or pull out a book, both international signs for “Stop talking to me, random person I don’t know.” I know that seems phenomenally rude, and it’s not meant to be, not really, but I don’t want someone prattling on and on in the side of my head about nonsense I don’t care anything about. I don’t do it to other people, so I hold the expectation that no one will do it to me.
I suppose part of that is because I don’t do small talk very well, even with people I know, so having to come up with witty conversation when talking to someone I’ve never met before fills me with a metric ton of anxiety, which is not something I need.