the answer to your question is rather simple.
people are lonely because they cannot accept others. they cannot even accept themselves. they are always trying hard to 'be accepted' in the herd. they are afraid to be individualistic.
they are their own enemy and hence they are lonely.
it's an attachment to our own inferior complexity thought. if one just breaks free from it by telling ourselves:
accept our weakness like we accept our strength. be what we are and be honest about it. if we can do that, we have accepted ourselves as what we are. only when we can accept ourselves, then others would also be able to accept you. when that happens, WHAT IS LONELINESS?