Human psyche is not rational. Reason takes work that most are not willing to invest in most of the time, regarding most things. Not even scientists, whose job is to be rational about things, live their lives fully rationally, or even "50+% rationally". Yes, it's not rational to feel good when doing good things for someone. Yet, most people do feel good when doing good things for someone. It's called empathy. And while that feeling is not rational, it is very handy. I don't see how you could have humanity as we know it without it. Whatever the reason for its existence, I'm glad that it exists. Who knows, maybe that's just the anthropic principle in action here? Maybe without it, you really wouldn't have humanity to wonder about it.