So instead of expanding outwards, the cities just became a lot denser, and economics forced up the price up of the land because the land potential is so high.
What it takes is a gutsy mayor to implement policies such as requiring at least 1m side setback on houses and 3m for apartments, having caps on the floor-space ratio to 50% instead of 98%, not allowing subdivisions on lands that have less than 15m frontage or 600m2 total area etc. This would basically see the housing market crash - lots of people will lose lots of money. But its a necessary evil.
The other angle to this is welfare being given based on the area you live in. Instead of housing support (in the form of tax and utility cost concessions) being distributed based on someone's personal financial situation, the means-test is based on the land classification that the property is built on. The land classification doesn't change whether the house is old or new, or if you build an apartment block on it. Which basically forces higher density in areas with better tax and utility cost concessions - aka poorer areas. In Colombia, this means that buying land in the highest-class areas costs as much - or in many cases less - than middle-class areas. This also introduced an almost caste-like system where people would only hang out from people from their own classification and would look down on people in lower classifications.
I appreciate shared-housing is a thing in Dublin (it is in Sydney too, and I have similar feelings to you about it) but the situation in many parts of Latin America exists for somewhat different reasons.