PALO ALTO, Calif.—In the three decades he worked as a software engineer in Silicon Valley, Fred Smith never imagined he would spend his golden years homeless.

But three years ago, Mr. Smith could no longer afford an apartment here, so he moved into an aging Winnebago camper. The 70-year-old showers at a gym where he has had a longtime membership. For most meals, he eats $1.20 orders of eggs or fish patties at McDonald's.

As...