Mjolnir is a very powerful magical object which can not be wielded by anyone. Mjolnir holds the power of God Tempest who year’s ago attacked Asgard; when Odin captured the storm in a piece of Uru.
The Uru piece was a gift from dwarves of Nidavelliar after Odin saved them from the invasion of trolls.
Odin then ordered them to forge Mjolnir from that chunk of Uru metal; as it was necessary to contain the powers of God tempest safely.
Once the Hammer was made Odin tried to wield it, it was uncontrollable as God tempest was still retaining some of the power.
Odin used the hammer to defeat the frost giants & after that, the hammer was stored away at the place where God Tempest died for many untold years.
Mjolnir was too powerful a weapon to be wielded by an evil so he eventually after some time cast the worthiness spell.
After many centuries it was passed on to Thor who proved his worthiness after numerous trials.
The big question here is what makes you worthy of Mjolnir; Marvel comics provide you the answer in the complex plot of War of the Realm.
It took a War for thor to understand what makes you worthy after he was no longer able to wield it.
Jason Aron in 2012 started Thor Saga which came to an end with the miniseries of War of the realm.
The sole purpose of this miniseries is to answer what makes you worthy? Why was thor not able to lift it just cause he heard something & lost confidence.
Aron’s Thor is fighting against the God Butcher Gorr in the opening scene; Gorr is someone who lost all he loved on a lifeless planet where he lived when he asked Gods for help they were not they so he started worshiping hate deities.
After he discovers Newcrosword he was unstoppable & started killing Gods brutally for being selfish & apathetic towards him.
It took three Thors (the Avenger, the Young Viking God & All-father from Future) from different timelines to defeat Gorr at last.
Afterward, Gorr’s accusation of God’s being hateful, vengeful & selfish people doesn’t deserve to be worshiped by immortals haunted Thor for a very long time.
Later Nick Fury whispered something that made Thor lose his confidence & was no longer able to field Mjolnir.
During this time Jane Froster became the God of Thunder while Thor finds a replacement for his hammer. Jane sacrifices it to stop the dangerous monster Mangog.
The final fight between Malekith & Thor is still not over & Thor doesn’t have his own mighty hammer so he once again calls the Thor from another time who is worthy but hasn’t wielded the hammer before — he believes worthiness can only be earned.
During the battle with Malekith when a monster attacks Freja his mother young Thor was so enraged by this that he picks up All-father Thor’s Mjolnir & wields it to defeat the symbiote monster.
You are worthy when you do good for others with the best intentions in your heart & not for your own glory.