Where did the money come from, what kind of economies, why did they run out of money?
Projects like temples and pyramids, as with public monuments today, represent a choice about how labor effort in a society is directed. Some labor is required to produce food, shelter and clothing that are necessities for sustaining life. Beyond this labor effort can be directed to producing other items that individuals or societies value. Every society through time has produced a surplus beyond that needed for subsistence. At the most fundamental then, it is by directing some of this “surplus” to the production of temples and pyramids that Romans and Egyptians “paid” for them.
A related question, of course, is how societies organize choices about the allocation of scarce resources, such as labor. Ancient Egypt and Rome were class-based societies in which a small elite commanded most of the resources. Slave labor and taxation imposed on the mass of society helped to concentrate control of resources in the hands of a small elite, and this elite then made choices about how to use the available resources.
Much the same could be said of Medieval Europe, China, or other pre-modern economies, as well as some modern economies.