Dwarves were originally the amoral maggots born from Ymir's corpse who devote their entire lives to smiting and will give you magical items under cursed terms or the rape of your women.
Gnomes were specifically invented to be the humanoid embodiment of the Earth element in the 1600s by Paracelsus, using the typical depiction of of little folk of the time.
Eventually "short men dressed like a medieval peasant; usually with a beard" became how all wee folk were depicted, with gnomes becoming "genial short man with beard who cobble shoes and lives in toadstools" and dwarves were "grumpy short men who live in the mountains and mine things" (and elves being the same, except sometimes naked, never bearded, and doing magic). This is why Disney's version of the Seven Dwarves look like what we now stereotypically think of gnomes as looking.
tl;dr they weren't the same until people keeping folklore got lazy