A lot of this is due to how US schools are funded, which is primarily by property taxes. That plays into the strict location requirements, since you could imagine a small school funded by a small property tax base being overwhelmed by students from outside the school's tax base choosing to go there and not having funding to support them. It also plays into the quality discrepancies: wealthy areas have nicer houses and therefore pay higher property-tax-per-capita (sort of, there's also racial discrimination dynamics here), so schools in wealthy areas have more money per student and can hire better teachers, have better teacher:student ratios, nicer equipment, etc. There's some state/federal funding of schools I think, but most funding is from property taxes, at least in the places I've lived.
In general, I think most confusion non-Americans have about the US stems from confusion about how our government works: in a very real way schools are run by counties and towns, not federal or state governments. School boards are elected, and schools are mainly run on a local level. Asking why a student can't choose to go to a different school is a bit like asking why a German student can't choose to go to a French high school -- there's an administrative barrier between them.
It is relatively common to use the address of a relative or friend in a richer part of town to get your kid in the nicer high school that you cannot afford to buy a house or rent an apartment in. My immigrant parents did that for me on multiple occasions.