I really liked how the movie handled this, actually. There’s a touching scene where Thor sits there, quietly telling Mjolnir that he hopes Mjolnir will always protect Jane, no matter what. There’s a slight glow on the hammer and it’s clear Thor’s heartfelt words were taken as a spell for the hammer. I don’t think Thor realized it at the time; he still didn’t understand the scope of his powers, but Mjolnir remembered that spell and reformed to protect Jane when it sensed she was dying.
Thor’s spell implied the new imperative for the hammer was protecting Jane, other functions were secondary. That’s why it became her hammer and not his anymore.
Thanks for reading: Why did Mjølnir reform for Jane Foster in “Thor: Love and Thunder”, but didn’t do so for Thor?, Sorry, my English is bad:)