It's complex, there are both narrative and visceral elements. Just because of sympathy, emotions are infectious, contagious. So that lower emotions make us feel bad, and being around sad people makes us sad. In helping them, in elevating their mood, they return the favor and elevate ours. Most times.
There then is the conceptual emotional influences. We see them as images, as down and out, something unfair has happened to them, and they are decent human beings. We don't feel good about helping a nasty person that doesn't deserve it -- in fact, the misery of a nasty person is more pleasurable than their happiness, when we add the conceptual level.
Our intentions are fulfilled, and we did what we meant to. Just the small success, and accomplishment of an intention is in itself pleasurable.
Then there is the higher, noble reason, which has nothing at all to do with what it feels like. It sees people's true natures without joy or sorrow, and affects their, and wishes for their well-being regardless of how we see them, or whether we think they deserve it, or if they're lower or higher than us. It does right for right's sake, even when it isn't pleasurable at all.