As far as my understanding goes the war hammer would not come in to use until many centuries later, so why how did the Vikings end up with one of their principal gods using it as a weapon?
Þórr was firts and foremost a protector of mankind, the god of smithing, but also of fertility, strength, protection and courage. The Hammer is mostly a symbol of his nature and function, as well as a metaphorical representation of lightning/thunder, not his weapon by its primary function.
Thor himself is not a god of war, or even a particular warrior among the As, that would by Tyr, and to lesser degree Baldr. Thor just happens to be mentioned using Mjolnir to slay Jörmungandr, which become an iconic "hero fight" in popular interpretations of Norse mythology.
The simplest explanation would be that it "stands to reason" from mythogenic point of view that a thundergod would fight with a hammer, not that hammers were actually considered a viable weapon by the Viking.
source:
Thor as a god predates the Viking period significantly, and might even predate other popular gods like Odin. It is quite likely that the ancestral god for the later Icelandic Thor was the 'Hercules' that Tacitus refers to when describing the gods of the Germanic peoples (besides Mercury/Odin, and Mars/Tyr). Note however that Tacitus also refers to Isis/Nerthus as subject of worship, and we also have the numerous dedications to various mother goddesses, as well as the national gods like Saxnot or Yngvi/Frey, so it is not so straightforward to connect Roman gods to Icelandic ones. However, there is a 10th century description of the temple at Uppsala which also mentions the three gods Thor, Odin, and Frey, reminding of the three gods of Tacitus, in which Thor is in fact described as carrying a club. The club, unlike the warhammer, was actually an occasional weapon of war of the ancient Germanic peoples, as the clubs from the postwar sacrificial site of Alken Enge show. Hercules' club was also carried as protective amulet by Romans, just like the Thor's hammer was later.
On the other hand, Thor as depicted in the Icelandic stories seems very much a 'regular guy', not the war-god of the earlier sources. The Icelandic sagas are full of people who improvise weapons and fight with whatever is at hand, so Thor fighting with a hammer would not be out of character.
Besides, the boundaries between a club, a hammer, and an axe are pretty fluid.
Thor was a god of lightning, and the hammer relates to that. Hammers can give off sparks when working iron or rocks, and a big and heavy hammer can give off a sound which reminds of the sound of thunder.
As a weapon, Thors hammer was rarely swung around, but rather thrown at the enemy, before it returned to Thor, as if it were a boomerang. A convenient weapon for killing Jotuns.
An interesting fact is that increased contact with Christianity may have increased the importance of Thor´s hammer as a religious symbol - using it as a necklace would then have been a reaction to seeing cross necklaces.