One type of emotional pain comes from the feeling of separatess, being different (in negative way, if there is such), being not a part of. All alone in this pain. If you find out there's someone else who's in so much pain, you've now found someone similar to you. In a way, you're part of group, and already the pain of loneliness has lessened.

More importantly, other sort of pain comes from failure. Failure is lack of success, and success can only be evaluated with comparison to other people. And in like any competition, you can win in two ways: improve your score, or lower competition's. And since your pain came from failure, if there's someone else who's in as much pain as you (or preferably more), it must mean he's as much of a failure (or more so). That, in turn, increases your relative success score slightly. You've won.