Fantasy is a literature of secondary worlds. The setting or secondary world of a work of fantasy plays a material but distinctive and necessary role. The sapient characters don't merely move across this world as a backdrop or exist in opposition to it. On the contrary, they are part of its warp and woof. In this sense we can say that fantasy is "ecological" literature, "comedy," literature that affirms man's dependence on his environment. Fantasy, even grotesque fantasy, is Consolation in that it reaffirms the goodness of all that is.
The secondary world represents a simplified, "closed" model of reality in which we can see very clearly the ties between it and its denizens. This closure frequently expresses itself through the secondary world being literally insular or confined (Barsoom, Tormance, Gormenghast, Earthsea, Narnia, Perelandra, Arrakis), or isolated in a remote epoch with a transparent history and cosmology (Atlantis, Middle Earth, Hyperborea, Hyboria, Zothique, the Night Land, the Dying Earth). There is something dissatisfying about a fantasy that tapers into the "messy" real world.
The sapient races are part of the secondary world and serve to simplify society by dividing it into easily identified castes with stark differences and formalized relationships. They also help the reader regard man as one species among many in a rich, diverse world.
The secondary world is part of an affective structure operating on an existential level. Fantasy aims to help the soul take stock of her own ambient reality, helping her to perceive and appreciate things as they are in themselves. It is Escape and Recovery in that it enables her to escape from the prison of familiarity and to recover herself and the simple things of life. It is the opposite of the White Witch's bad magic food, which ruins the taste of good, ordinary food.
Style plays a crucial role in this structure. An unfitting style results in a flat fantasy. The point isn't that trees are flat in fantasy if not properly described, for flat trees figure in many good "literary" novels. The point is that flat trees simply are not allowable in fantasy as such. Fantasy is literature in which we care about the trees.* For this reason and others, fantasy is a fully incarnational art. The tale cannot be divorced from the telling any more than a man's soul can be divorced from his body.
The objection to "messiness" above is not to say that fantasy is somehow "tidy" in the Disney sense. It also differs from fairy tales and myths and epic romances through its meticulous naturalism, which at times devolves into slum naturalism. It is more akin to the Divine Comedy or Don Quixote than Orlando Furioso. It places the reader in a fully realized environment.
Fantasy often arises as a metaphor for an author's system of belief or philosophy, but it is diametrically opposed to allegory, and its elements quickly acquire a life of their own. They serve as an embodiment or living incarnation of transcendant propositions. The system of belief is but a material element, and one needn't share it to enjoy the work. In the end it feeds into the affective structure: the reader "believes" whatever the book presents as true, within the context of the secondary reality. Fantasy in which propositions gain the upper hand (as in Perelandra) ultimately fails. On the other hand, fantasy lacking a substantial purpose or underlying philosophy runs the risk of silliness or frivolity.
* "Very little about trees as trees can be got into a play." From Tolkien's "On Fairy Stories."