The items that make this expensive have to do with the standards that must be met, zoning and approval processes, and so on. These are things that a private construction firm, under contract with SF, does not find easier or cheaper.
Personally, I like the idea of SF maybe getting in the way of housing construction a bit less. But I also understand that voters seem to like the system as it is. Plus, only some of these laws are readily changed by SF - the plebiscite for public housing law is a state prop from the 70s. Many of the other requirements are also propositions at either state or local levels.
As you say, it's completely true that the government can change the relevant laws. It's just perhaps more subtle than that, as there are multiple levels of government involved and some of the relevant laws are quite challenging to change.
You are skipping over the part where the government can change the relevant laws that make public housing expensive. Public housing also doesn't have to be built by the government directly so if private construction firms can do it cheaper the government can let them build the housing.