A confluence of different factors and portrayals. You might want to look at mine and u/itsallfolklore's answers on Had the legendary "dwarfs" of Western Europe been associated with Jews before Tolkein (or possibly Wagner)? and When did the depiction of dwarves as Scots begin in the fantasy genre?, which I think largely covers a good bit; as far as living underground there is fairly substantial amount of material for various earth-spirits in European folklore and mythology (and many cultures besides those have their own subterranean supernatural dwellers as well), and this understanding of dwarfs, gnomes, or related critters living underground appears to have been fairly well-ensconced by about the 1890s...but it was far from a universal image; in Andrew Lang's fairy books (1889-1913) for example, they are often as much creatures of forest as underground. But if you look at Lang's version of "Snow-White and Rose-Red" from The Blue Fairy Book, they are described as:
I must go to the wood and protect my treasure from the wicked dwarfs. In winter, when the earth is frozen hard, they are obliged to remain underground, for they can't work their way through, but now, when the sun has thawed and warmed the ground, they break through and come up above to spy the land and steal what they can: what once falls into their hands and into their caves is not easily brought back to light.
Which is pretty close to what has become the standardized image of the underground-dwelling, bearded, greedy, dwarf - especially through the offices of Walt Disney's Snow White and the Seven Dwarfs (1937; and actually based on the Brothers Grimm version of the story) and J. R. R. Tolkien's The Hobbit (1937) and The Lord of the Rings (1954-1955), and their innumerable adaptations, pastiches, etc.
It's important to remember that these are not the only depictions of dwarfs as a fantasy people - in the third voyage of Sinbad he was captured by dwarfs that lived on an island, and in Gulliver's Travels (1726) the Lilliputs are short on stature but otherwise not much different from us Yahoos. But the underground, bearded, greedy version caught the popular imagination through several prominent works, and helped set the stamp on what people default think of as dwarf appearance and behavior.
/u/AncientHistory and I frequently tackle these sorts of questions from different but not contradictory perspectives, and my hat is off again in the general direction the excellent answer provided by my colleague. /u/AncientHistory typically and expertly connects literary roots so that it is possible to understand the origins and relationships that one can consider to understand the unfolding of fantasy literature.
To this I will add a note or two. The idea of underground supernatural miners is old and it was widespread. Besides the Cornish example described in the link that /u/AncientHistory provided, it is useful to note that Georgius Agricola, a sixteenth-century German scholar, describes these sorts of underground miners in his De re metallica. This idea, then, was part of an old cultural bedrock of Northern Europe (and elsewhere for that matter!). oral tradition communicated stories about these entities long before they were documented in print, either by folklorists (including the Brothers Grimm) and by fantasy authors. This idea was not created out of nothing. In folklore, the supernatural miners were typically regarded as wizen men with long bears and tattered clothes. They jealously guarded the underground wealth and would punish greedy men. They could, if treated with respect, co-exist nicely with their human counterparts.
And a word of caution: many supernatural beings - not just the ones underground - were regarded as spending a great deal of their time in small form. Small stature does not link all the small actors any more than other attributes do - including the ability to become invisible. Many supernatural beings with little direct relations were small; the folk regarded the surface entities as distinct from those who worked underground regardless of this shared characteristic.