The purpose of "Jabberwocky" is delight and fun. It is nonsense verse of the highest order. According to Martin Gardner, editor of The Annotated Alice, "Few would dispute the fact that 'Jabberwocky' is the greatest of all nonsense poems in English."
Carroll wrote the poem when he was 23 years old "for the amusement of his brothers and sisters." He later incorporated it into Through the Looking Glass and What Alice Found There. Alice finds the poem in the first chapter when she first enters the Looking Glass House. It's written in mirror-image, and she thinks it's a different language, but when she holds it up to a mirror, she's able to read the words. Ironically, however, although she can read the words, the poem doesn't make any sense. Yet, as she says, "it seems to fill my head with ideas--only I don't exactly know what they are!"
This is the brilliance of "Jabberwocky." The nonsense words Carroll uses work intuitively to convey meaning even though they are nonsense. Whether by sounding similar to words we know--like galumphing, slithy, and gyre--or by making use of onomatopoeia--like uffish, whiffling, burbled, and snicker-snack--sense is communicated.
Carroll uses a number of silly poems as a motif in the second Alice book. In Chapter 6, Alice meets Humpty Dumpty and calls upon him to help her understand the words she doesn't know from "Jabberwocky." Humpty Dumpty then entertains her with a poem of his own, which he insists "was written entirely for your amusement." So one could say the purpose of "Jabberwocky" is to help tie the story together, or that it gives Alice a puzzle to solve, or that it teaches her that there are many things in the world that she can't figure out. All such explanations are as needlessly complicated as some of the definitions Humpty Dumpty gives for the words in "Jabberwocky." The real answer is that the poem is "written entirely for [our] amusement."
This poem shows that we can understand our language to some extent without knowing the meanings of all the words. Like Alice, we can get the drift without being able to pin down the exact meaning of any lines. To make the poem as clear as it is, Carroll depends on the suggestions that sounds create for meaning. More importantly, however, he uses key standard words to give us the essential idea (such as “Beware,” “sword,” “through and through,” and “dead”), and he also scrupulously observes proper syntax, so that we may construct meanings for the nonce words. Ironically, some words that Carroll created for this poem have become so integral to our language that computerized spell-checkers do not flag them as misspelled.