Loneliness is when there is a gap between desire for companionship/connection and reality.
I've done both extended periods of home office and a period of co-working in an open plan space. I didn't feel lonely in the home office. I guess because I did it by choice and had the agency to opt into joining a co-working.
I think that loneliness could be a symptom of lack of connection. And this need for connection can in some cases be fulfilled online or even through reading books. Participating in forums like hackernews or effect-ts satisfies some of the handful facets of connection that I need. It gives me a feeling of not being totally alone with some of my ideas.