It was never Sam's main objective to become a maester, sure that's why he went to Oldtown but that was a side mission.
SAM: I wanted to ask you something. To ask something of you. Send me, Gilly, and the baby to Oldtown so I can become a Maester. That’s what I’m meant to be, not this.
JON: I need you here, Sam. If you leave, who’s left to give me advice I trust?
SAM: Well, there’s Edd.
Jon gives Sam a look.
SAM: I’ll be more use to you as a Maester. More use to everyone now that Maester Aemon’s gone. The Citadel has the world’s greatest library. I’ll learn about history, strategy, healing. And other things. Things that will help when they come.
Jon stares at Sam, saying nothing.
SAM: If Gilly stays here then she’ll die. And the baby that she named after me will die. And I’ll end up dying, too, trying to protect them. Which means that the last thing that I’ll see in this world will be the look in her eyes when I fail them. (pause) I’d rather see a thousand White Walkers than see that.
Jon inhales, exhales, then nods somberly. Sam smiles.
Game of Thrones, Season 5 Episode 10, "Mother's Mercy"
As you can see Jon only agrees to send Sam after Sam explains that he will learn things to help, Jon was reluctant initially.
Note that this proves true in Season 7 Episode 5, "Eastwatch", when Sam leaves the Citadel after learning the maesters are dragging their heels with helping him become one and after finding the books that will help him. The following transcript details that Sam takes books before leaving reinforcing this fact.
SAM is walking through a dark library. He heads to the restricted section and unlocks the barred gate. He begins removing books and scrolls from shelfs and stuff them in his satchel. After retrieving what he needs, SAM quickly walks to the exit of the library. He pauses before he leaves and turns around. He glances back at the library. It is many stories tall lined with countless shelves of books. SAMWELL looks at the library one last time, turns and walks out of the door.
CUT TO: EXT. CITADEL
SAMWELL is loading a wagon with his things. He walks around to the driver seat. GILLY and SAM JR. are already in the wagon dressed for the road. SAM climbs aboard and takes the reins in his hand.
GILLY: Are you sure you want to do this? You always wanted to be a maester.
SAMWELL: I'm tired of reading about the achievements of better men.
Game of Thrones, Season 7 Episode 5, "Eastwatch"
Note that Sam has also already got some helpful books in his possession and has already sent information up to Jon Snow about the whereabouts of Dragonglass on Dragonstone.