> Towns are an interesting case where the free market system breaks.
What you're observing isn't the output of a free market; for that, see towns built primarily up until about the 1930s; these are traditional, walkable towns, with a coherent downtowns and organic patterns of settlement.
Since then, zoning laws and land-use planning have drastically altered the common patterns of development and led to the rise of master-planned subdivisions that are all too common today.
If not for the artificial segregation of residential and commercial uses and for equally artificial restrictions on density of development, modern suburbs would likely be smaller satellite towns, each with its own coherent walkable core, instead of megatowns with purely residential sprawl extending great distances away from the only urban core permitted to be developed.
I don't know whether it's the same outside of cities, but based on my limited experience, Japan appears either to have no zoning laws at all or to have such permissive ones that basically anything can be right next to (or, very often, on top of) anything else. Experiencing it after living in the US was a very jealousy-inspiring experience.
You can see similar patterns in dense urban environments built up in the US prior to the rise of zoning, too. New York, as an obvious example. But I bet without zoning, much of the rest of the US would probably look like New England, which had already substantially "suburbanized" well before the fashion for land-use planning took hold on this continent.
I think zoning has a lot more deleterious effects than just creating alienating urban spaces, too. It influences everything from transportation infrastructure to energy consumption to individuals' emotional states to macroeconomic patterns. Out of all the utopian policy innovations that have backfired over the past century, zoning is probably the worst.
> One counter example to your claim is Houston. ... [T]here is no legal master plan that divides the city to different uses.
Houstonian here. What you say is correct --- but many, many neighborhoods in Houston have legally-enforceable deed restrictions : When you buy property in those neighborhoods, you are deemed to have agreed to a (typically, very-detailed) set of restrictions about what you can or cannot do with, or on, your property. Local homeowner associations can be pretty vigilant in seeking out and going after violators.
Moreover, some neighborhoods are in fact separate, incorporated cities that do have zoning laws. (I live in one such.)