In land where it is required to use as little space as possible, why would many consecutive buildings be several yards apart?

Most of the other answers are rather entertaining while only touching on the truth.

The reason is fire and human safety.

Most long-lived cities that don’t have these spaces, called setbacks, have either burned down or were demolished to place setbacks.

Setbacks are areas around structures or properties used to stage fire fighting activities and as routes for building occupants to use to get away from endangered structures.

For the more observant, yes there are many examples where buildings come up to the edge of the property or a neighboring building. Typically one of two conditions is occurring here. First, the building is up against a location that is assumed to never possess a building, such as a street front. Second, and this may be required even if the first condition was met, the wall located along the edge must be constructed to a level where fire isn’t expected to destroy it, won’t collapse along with the rest of the building, and is heat resistant enough to hold off the heat of a raging fire for four hours (basically a fire on one set would need to burn for four hours before the transfer starts lighting paper on fire on the other side).

In modern construction this usually requires a solid concrete or masonry wall 8″ thick and extending 2′-4′ beyond any lesser construction with no openings, doors or windows. (There are alternatives, but I’m not going into those.)

History has taught us that without those setbacks, your city is going to burn down, likely with many of its occupants, at some time in the future.