This is the kind of thing forums like this were made for. That’s a really good question.
I’m not really sure of the answer, but I think you may be giving people too much credit. As you said, even when you tried to explain it to the woman she didn’t get it. I highly doubt that even on a subconscious level people are thinking in their own long-term economic self-interest when they act in benevolence at least in this type of situation. I sincerely doubt most of the government growth and regulations would not stand if people had the mind that you’re talking about. I think most people think wealth is about money and that businesses have it, and they personally do not…and that 5 quid is not going to make anywhere near as much difference to them as it would to you (as discussed here.)
By the same token, I do not believe that someone who actually does give the money back as you did has a better understanding of economics and is thinking in those terms. I think the much more likely explanation is that they understand basic “right and wrong” and it is much more of a moral question than anything else. I personally think things like that are more than anything a product of how you are raised. Now, you might make the case that even that is in self-interest because there is some form of impending guilt that they wish to avoid…and that may very well play a factor.
Finally, the reason I made the qualifier “in this type of sitution” is because when it comes to benevolence in a much more personal sense…as in dealing with a person or a non-profit organization, I think people do think about themselves. As noted in this Stossel segment on charity, poorer people tend to give more because they believe they are likely to need it themselves at some point.