The Hukou (户口) system that you’re talking about wasn’t established because of demand for housing in Beijing. It’s not really clear why it was established and has origins that date back hundreds of years. It essentially serves as a social control mechanism and to promote people living, and thus laboring, in rural areas. Though it dates back to immigration control between states in “China”. (When they were different sovereign entities.)
They’re all migrant workers and are allowed to be in Beijing without Hukou. Hukou Just establishes certain privileges like home ownership and school access.
The best way to think about Hukou for Americans is that Hukou is like if California required a Texan or Floridian to get a Visa or become a “California Citizen” before working there, buying a home there, or using public services there.