How does it get from SHIELD custody, to Asgard >and back to SHIELD? Or is this simply a plot hole? >
I was in Norway first in the hands of humans who worshipped the Asgardians.
Then taken by Red Skull in the first Cap movie. Then recovered by Howard Stark and used by shield in some capacity up to the 1980's and 1990's where its used in project Pegasus as seen in Captain Marvel.
Then Loki steals it in the first Avengers movie from Shield, after he's defeated in NY, it's in Asgard. Loki takes it before Asgard gets destroyed and then coughs it up to Thanos in Infinity War.
So it went from Norway to Shield to Asgard to Thanos.