It seems pretty simple to me. The power is inside Thor, and the hammer was created to help Thor channel that power. Later, as punishment for Thor's arrogant, wreckless, and violent behavior, Odin stripped Thor of his power and sealed it inside the hammer, then made an enchantment that would give the power to any worthy person (Odin was basically implying that Thor himself would never be worthy, so he would give the power to anyone else who was). However, after the hammer is destroyed by Hela, the enchantment is rendered moot and Thor eventually learns how to access his powers on his own.
Then Thor retrieves the hammer from the past, when the enchantment is still in effect, so when Cap picks it up he recieves the power that is still locked inside the hammer.