It is just something that Dragons do in Tolkien's legendarium.
It's in their nature.
From
The Hobbit : Dragons steal gold and jewels , you know, from men and elves and dwarves, wherever they can find them; and they guard their plunder as long as they live (which is practically forever, unless they are killed), and never enjoy a brass ring of it .
Indeed they hardly know a good bit of work from a bad, though they usually have a good notion of the current market value; and they can't make a thing for themselves, not even mend a little loose scale of their armour.
...
There was a most specially greedy , strong and wicked worm called Smaug.
Dragons are simply greedy by nature, and that combined with an inability to "make a thing for themselves" has apparently driven them to horde precious items made by others.
scifi.stackexchange.com/users/4383/NominSim
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.
scifi.stackexchange.com/users/None/
It's an expression of Smaug's power.
Collecting something you value is an intrinsically motivated act.
You build up a collection of things you enjoy purely because you enjoy them.
The opinions of others have no impact.
To collect something valued by others shows extrinsic motivation.
Not only do you deprive others of the contents of your collection, but by gaining their admiration or envy, you gain power over them.
scifi.stackexchange.com/users/10570/Richard Hare
Tolkien's day job was as a teacher of Old English literature, among other things.
The third part of the Old English saga/poem 'Beowulf' tells how the hero had to deal with a dragon who was angered because some low-life had sneaked in, and stolen a golden cup from his cavern-hoard of treasure.
The dragon emerged and devastation ensued.
Eventually the dragon is slain, but the hero dies.
The idea of dragonish desire for treasure was certainly present in literature before 1000AD, and was also picked up in C.S. Lewis' Voyage of the Dawn-Treader.
Perhaps it was all metaphorical for humans with an overwhelming lust for glittery stuff.
We all know some bling-heads!
They probably had them back then too.
Some of the Anglo-Saxon gold-work with enameling and carnelian insets are unbelievably intricate and beautiful, check the Sutton Hoo treasure on google images.
I can see why dragons would covet it.
There are a lot of scholarly articles on the dragons of Old English literature, try google scholar.
The bibliographies of a few articles should get you on the road to a better answer.
scifi.stackexchange.com/users/17362/Maria Mackay
Not a Tolkien source, but I fondly remember the explanation used in The Flight of Dragons , a favorite movie when I was a boy.
Breathing fire, dragons tend to burn up bedding made from conventional materials.
They make their beds of gold as it is a softer metal that won't ignite.
scifi.stackexchange.com/users/10616/phasetwenty
Wikia states (no Tolkien quote) that there was one side benefit to the hoarding (possibly not intentional) -
the jewels stuck to Smaug's scales when he was lying atop of his treasure, making him even less vulnerable to damage than scales alone.
scifi.stackexchange.com/users/976/DVK-on-Ahch-To
In  The Hobbit ,  the Dwarves, Bilbo and Gandalf are on a mission to rob Smaug . But why did he have so much to steal from? He's a Dragon! He is not the kind of dragon that  eats gold and gems . He doesn't need wealth to buy a luxury cavern and/or pay his servant.   Why did Smaug gather his treasure?
Why did Smaug gather a treasure of gold and other precious objects?
scifi.stackexchange.com
<the-lord-of-the-rings><tolkiens-legendarium><the-hobbit><dragons><smaug>
scifi.stackexchange.com/questions/27653
scifi.stackexchange.com/users/45/DavRob60
This is just something that Dragons do in Tolkien's legendarium and this can be seen as an expression of Smaug's power. Smaug wants to express his power.
Smaug wants to express his power.