Aside from dragons gathering treasure being a generic mythology trope (e.g. Fafnir's hoard, which Tolkien would have been well aware of), an in-universe explanation is also appropriate.
Dragons in Tolkien do gather treasure; his other major dragon from the legends of the First Age - Glaurung - did the very same after he sacked Nargothrond - piled up all the treasure and sat on it. In the Third Age Scatha the Worm is also mentioned as having a hoard, which led to a fued between the Northmen and the Dwarves (the horn that Merry was given is mentioned as having come from this hoard).
So it's just something that Tolkien's dragons do. But why?
As creatures of Morgoth there is very likely an element of his spirit in them (this is nowhere confirmed in canon, but I'm imagining Morgoth feeding reptiles to create dragons in much the same way as he fed a wolf to create Carcaroth, although their obvious intelligence and sentience suggests a possible Maiar source (I'm deliberately ignoring the Lost Tales concept of dragons here); either way we don't know and we've moved away from the topic a bit now); when Morgoth lusted after and stole the Silmarils from Formenos, he also took a lot of other jewels with him, which he also did not need and which he begrudged having to feed to Ungoliant. So there's a clear element of basic avarice, especially avarice for items one does not actually need, running through Morgoth and his dragons.