The wealthy class of the past had spend some of the wealth to be remembered via public works or patronage of art.
Through their vanity or just a goodwill they wanted to be remembered for something.
This doesn't seems to be a rule, but an exception.
All of the social contracts of old societies were broken old time ago. Helping poor is either PR stunt or dirty work of middle class. Or a ploy to extract more wealth (lookup disaster capitalism).
Globalization decoupled the 'haves' from the place they are living. They can uproot and travel away to another community. Be it SF or next SF.
This was much harder in the past. Business and family ties would make it harder to just move to Spain.
That tied the 'haves' to 'have-nots' in a way. So the 'haves' might be incentivized to make the place a better for everyone - this would be that saying that the philantrophism
is just selfish behavior as you make your own environment a better place, only through indirect means.
But this is largely no more.