Some states have open enrollment. In my state you can apply to another district and if the district has space, they accept kids from other districts. For highly coveted districts, there is usually a lottery system. School districts actually make money from taking open enrollment students, because they get money from the state for those students but they don't usually spend that amount of money on that particular student. The building has space, or a particular grade has space, so they don't need to hire new teachers or build new buildings. Plus, they don't need to provide bussing/transportation for those students so they save on those costs. Some districts try to recruit open enrollment students. We also can open enroll into different schools within our own district as long as there is space.
So I currently have one kid in one school and the other kid in another. I've had problems getting DD in anywhere. Third grade is packed in just about every building for some reason. Must have been a baby boom year.