The company is not a business or people visiting. Company is just someone else. IF you meet someone sad, and you visit, are you more sad or are they more happy? When you are sad do you want to have company? Sometimes. But you can not easily be cheered. Your company may end up like you. You may both end up sad.
That is what it means, but this is not the only way it is used.. It is also used when you try to convince someone to not do something because you both already know of people who have paid consequences for the activity. The person will do it anyway. "misery loves company"