I don't think he would have given Jon the sword just to keep him at the Wall. I think giving him Longclaw was just about repaying the debt of saving his life. I think that if Jon abandoned the Watch, Mormont would have had Jon executed.
You also don't get a pet dire wolf or dragon without plot protection. We get it. But it's still all totally believable in the world GRRM created. There's a perfectly logical explanation of how Mormont had the sword and would just give it to Jon. Don't overthink it...