An Artist's Depiction of Atlantis
Perhaps the most common trope in scifi and fantasy media is an ancient and now extinct or almost extinct race who were able to utilize highly advanced magics or technologies. This trope is so common that it permeates even the most famous and lauded scifi/fantasy franchises such as LOTR, ASOIAF, Star Wars (in the EU), Issac Asimov's works, and countless others. So why is this trope so widespread? And what is this trope based off of?
The obvious real life inspiration is the fall of the Roman Empire and how that effected those who lived in and ruled the former empire. The problem is that exactly how "dark" the "Dark Ages" really were is still being debated by historians today. For example much of the literature was preserved either by the Eastern half (and later the Muslims who conquered it) and monasteries in the West. Additionally, they were able to build truly impressive castles and churches, some of the later ones being comparable in size to Roman and pre-Roman structures. The fall of the Western half of the Roman Empire certainly had a massive impact on Europe and the world, I just do not know if it could be considered truly apocalyptic. One example of the effect of the fall of Western Rome is that the literacy rate drastically dropped. Another example is that much of the infrastructure such as aqueducts fell in to ruin and engineers and architects were unable to replicate them. To further illustrate the point, militaries and and the population of many cities would not rise to the size of their Roman equivalents until hundreds (and in some cases over a thousand) years later. The truth is that although the fall of the Western Roman Empire may have had a massive impact on the course of history, technological development, and philosophy, it had little impact on the day to day lives of the common people living in the former empire which is why I do not think it can truly be considered an apocalyptic and civilizational ending event. However, it is probably the closest parallel we have to the trope of a super advanced race dying out and leaving behind magnificent works that we still struggle to replicate or understand to this day. Maybe a more direct comparison to that sentiment is some of the wonders of the ancient world.
Even to this day we are still struggling to explain exactly how our ancestors built things like the Pyramids of Giza, Stonehenge, the Hanging Gardens of Babylon and other sites. With Stonehenge, there is not even a consensus about the purpose of the structure. There are theories, but no singular definitive agreed-upon purpose. Looking at those ancient megalithic structures is about the closet we can come to understanding the feeling of being preceded by an extinct but highly advanced civilization. Additionally seeing those and other megalithic sites probably inspired many authors to utilize this trope in their works. Another interesting area this trope pops up is in mythology.