They didn't, always. There is evidence that the the south east part of Colosseum (just as an example) finished in AD 80 collapsed in the AD 217 earthquake because the foundation was less firm than the other parts. They fixed it up, of course, and we have what we have.
But the answer is sort of built into the question. The buildings that didn't hold are no longer with us, and traces are long gone. Residential housing in Rome, high right tenements were often a dicey proposition, not least of all when fire hit. And fire hit a lot. We remember the fire of AD 64, Nero's fire, mostly because it wiped out a huge swath of the city. There were plenty of other fires, small scale and large (one in AD 79, the same year Vesuvius blew, making a serious headache for the emperor Nero). Marcus Crassus, born wealthy, became more so by the expedient of waiting for houses to go on fire, then sending his private firefighters to the scene and cutting a deal with the owner - sell it to me now for cheap (in which case he sent his crew in), or watch it burn down to utter worthlessness.
Nero, by the way, instituted building codes after his fire to prevent the catastrophe from happening again - wider streets and no shared brick walls - every unit had to have its own masonry. It presumably helped at least somewhat.
Other than that - trial and error and experience. And keeping the things relatively low.