This kind of loneliness has as much to do with rejecting oneself as it is being rejected by other people.
Each of us have emotional wounds inside that are sensitive. We typically wrap layers and layers of personality, activities, and rationalizations to protect it. And if it gets through that, it triggers some protective emotional outbursts or behaviors. Or we shut down, like the woman in catatonia.
It is usually painful enough that the mind does not want to be aware of it, and when hitting upon that, will naturally veer away from it.
You can be fundamentally lonely in a crowd of millions. You can be the meditating sage in some isolated cave for years, because you know at the core you are not alone.