Today we have skyscrapers and tall apartments because it's not a difficult task to get to the highest level (there's elevator), there's electricity and water pump to ensure life, and land has become more expensive so people build residents vertically.
But in pre-modern times, where such conditions are not met, what are the incentives to build and live in tall buildings?
For example, in Ancient Rome there were 10 stories high insulae, 100 stories high towers of Bologna in medieval Italy, and 14 stories apartments in 11th century Egypt.
According to Tom Holland, the Romans built insulae for the same reason we build apartment blocks today. Land in cities was expensive to buy, so to make the best return on investment, the owners built upwards instead of outwards. Building upwards meant that you could fit more people into your building, and hence get more rent, without having to pay exorbitant land prices. The quality of life in insulae was definitely worse than that in a house - insulae were shoddily built, and would often collapse, but for many it was the only housing they could afford.