This happens a lot. There is a disclosure called a CLUE report (comprehensive loss underwriting exchange) which looks for insurance damage.
The problem is that in older buildings, often this is just unfortunate timing on the part of the buyers (both the developers and the owners). I had a sewer inspection done on a 20’s era property recently. This was a camera inspection where they actually send the cam with a light down the sewer main. This is the most exhaustive inspection you can get short of actually digging up the lines (which is prohibitively damaging and costly). It passed with flying colors but the entire line (with its 83 years of wear collapsed a month later. While inspection and information are good things to have, in the end, some amount of purchasing is a crapshoot. While we try to minimize this, it is a necessary evil.