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.
I wouldn't be surprised if this would start happening next decade or so, were large chunks of land will be used as pseudo autonomous zones where rich wall themselves off.
It doesn't feel like SF has been able to capture any of the wealth being generated in a way that other cities like Vienna have, and now even when it's a century past its peak, people there still benefit. Certainly the homeless in SF don't seem to benefit even now, but maybe there are so many because SF truly is the best place to be homeless.