There are more lonely sitcom characters than you might expect.
The first one that springs to mind for me is Richie, in Bottom.
The whole show is pretty bleak in a Beckett kind of way. Two people who can’t stand one another are forced to live out their shitty existence together, and smash each other in the head with frying pans. It’s actually a pretty devatasting satire on toxic masculinity too.
Richie resorts to fantasy, and delusions of grandeur, in a flawed effort to shake off his loneliness, and as a result never seems to have the time to clean his underpants.
Dear John (both UK and US versions) features a cast of characters so lonely that they meet once a week in a run down community centre, pretending they’re looking for love, when all they really crave is company and attention.
Kirk for instance has created a whole new persona for himself, like Richie retreating to a fantasy world, but is still so flawed all he can do with it is go to the 1-2-1 club.
Red Dwarf began its run as an exploration of being stuck alone in deep space, the last human alive whose only company is a senile ship’s computer, a hologram of a dead bunk mate he hates, and a creature who evolved from the ship’s cat. It soon moved away from that, and Lister focuses less on this (though it does return now and again, and more so in the later shows). Kryten takes on the mantle, having been rescued from his own madness alone on the Nova 5, and his fear of being abandoned surfaces in strange ways.
There’s an argument to be made that Neil Pye in The Young Ones is lonely. He’s got a friend. One. Matthew in Newsradio too, and Granville in Open All Hours, as well as Alan in the first series of I’m Alan Partridge.
As a sitcom trope making a character lonely is a good one, from a structural point of view. It forces them to mingle with people they wouldn’t ordinarily spend time with, and it adds a motivating factor to otherwise seemingly stupid behaviour.