I can't remember whether Jorah was exiled before or after Jeor abdicated. But whether or not he did, Jeor himself says that it's not good for men of the Night's Watch to return home. If he knew he would not be going back to Bear Island, would it not make more sense for him to leave Longclaw with Jorah or Maege, thus ensuring its continued place as an ancestral sword?
I believe he had already taken the black and given Jorah Longclaw. But when Jorah was exiled he left the sword behind with his family. In the TV show, Jeor explicitly mentions that "At least Jorah had the decency to leave it behind."
Jeor's sister and nieces sent it to him at the Night's Watch. I assume he would have held onto it until one of his nieces had a son, but since he was quite old and they did not seem to be having children he gave it to Jon Snow instead as a gift for saving his life.
In the books Jeor explicitly states that the sword was left to his son Jorah when he took the black, only that Jorah left it when he fled. When Jorah left it Jeor's sister returned it back to him but Jeor hid it away.
"It is," the Old Bear told him. "It was my father's sword, and his father's before him. The Mormonts have carried it for five centuries. I wielded it in my day and passed it on to my son when I took the black."
He is giving me his son's sword. Jon could scarcely believe it. The blade was exquisitely balanced. The edges glimmered faintly as they kissed the light. "Your son—"
"My son brought dishonor to House Mormont, but at least he had the grace to leave the sword behind when he fled. My sister returned it to my keeping, but the very sight of it reminded me of Jorah's shame, so I put it aside and thought no more of it until we found it in the ashes of my bedchamber. The original pommel was a bear's head, silver, yet so worn its features were all but indistinguishable. For you, I thought a white wolf more apt. One of our builders is a fair stonecarver."
A Game of Thrones, Jon VIII
The scene in the show is less detailed albeit the same situation.
Jeor Mormont: It was my father's sword, his father before him. The Mormonts have carried it for five centuries. It was meant for my son Jorah. He brought dishonor to our House, but he had the grace to leave the sword before he fled from Westeros.
Game of Thrones, Season 1 Episode 9, "Baelor"
As for why he kept the sword when Maege returned the sword to Jeor instead of keeping it at Bear Island with the house, well we don't know. It could be because she has no sons so believes it should be in male possession.