It is more nuanced than simple denser cities are more expensive than less dense. Some parts and some dwellings of denser cities are more expensive, but it also depends on other available options for the population.
Ya, the slums of Manila and Mexico City are pretty affordable compared to the formal housing market. But I’m not sure that we s a good thing. Most developed countries also don’t allow for such places (anymore?).