Warning: The following material is heavily subjective and written by an opinionated idiot. Exposure to extreme subjectivity can be harmful to your mental health, please read with care.
When music closely matches your emotions, it kinda amplifies it and brings it to the foreground, it makes it easier to feel your feelings. If you are repressed and need to get those feelings out, music can work great as a pressure release valve, on top of this music also focuses your emotions. Emotions are rarely clean and simple, but most music has a clear emotion or feeling to them, and if that music closely matches your emotions, it can focus conflicted or confusing feelings into something less conflicted and simpler to understand, like smoothing a jagged surface.
If you are in lots of pain, that pain will likely be confused and conflicted and the myriad emotions can just cause more stress, playing appropriate music can sooth those painful emotions into a clear and calm misery, providing a release of sorts, the way I see it, its like finding someone struggling along rocky terrain on the way to throw themselves off a cliff and building them a road. The road makes their lives so much easier, but also lets them reach the cliff quicker.