Justifications in-story for why a dragon sits on a hoard, including backstories of how hoard and dragon came together, vary considerably. Curiously, there is no consensus as to why dragons do this. This trope is especially ingrained in Germanic Mythology - in fact it is hard to find a dragon in ancient Anglo-Saxon, German or Norse legends that doesn't guard gold. In some settings, dragons tend to guard hoards of treasure - typically by lying on top of it.