Charles Lutwidge Dodgson got his pen name by taking his first two names, translating them into Latin (Carolus Ludovicus), switching them, and re-translating them into English a different way. He was not the one who actually chose it -- he submitted to his editor, Edmund Yates, as one candidate among several for a pen-name, the others being Edgar Cuthwellis, Edgar U. C. Westhill, and Louis Carroll. Yates chose Lewis Carroll, thus sparing us Alice in Wonderland by Edgar Cuthwellis. Dodgson studied to be an Anglican priest, but concluded in the end that it was not for him; he became a mathematician at Christ Church, a position he seems to have detested, perhaps because he found himself intellectually lonely there -- Dodgson, despite a certain shyness due to his stuttering, was an extremely sociable person, with a wide network of friends and an immense correspondence, and any kind of isolation seems to have caused problems for him. (It seems, for instance, to have hampered his work in logic that he had no one to discuss it with except John Cook Wilson, who not only did not fully understand what he was doing, but was a bit patronizing about it, as well.)
Alice's Adventures in Wonderland was published in 1865, in part on the recommendation of George MacDonald; Through the Looking-glass was published in 1871. I'll be doing both. Despite both being nonsense-tales, they are elaborately constructed out of any number of logical, mathematical, and recreational puzzles. For instance, here is Carroll's own description of Through the Looking-glass as a chess game:
We'll see what we can pull out of the puzzle and riddle of the tales; it is not an accident that they are both structured on games, so let the game begin.