The law doesn’t forbid you from selling to a developer, but the law does forbid the developer from turning a single-unit house into an apartment. Or even a duplex, a lot of the time. Just look at the zoning maps. Around Golden Gate Park, the height limit is 40 feet, and a lot of it is single-family zoning.
http://sf-planning.org/zoning-maps
A lot of the time, it is more practical to take that single-family house and turn it into a fancy single-family house. Satisfying gentrification. https://sf.curbed.com/2018/4/25/17277290/glen-park-home-expe...
Local planning code determines what can and can't be done, not who you can sell to. This is true everywhere.
And I actually don't think eminent domain (over time) is a terrible idea. Make the area around Golden Gate Park look like Central Park and your housing problem is solved.