The writing goals:
1. Making people seek/value truth more. Getting them to equate knowledge with happiness, no matter how untrue this may actually be at times.
2. Reducing indifference/increasing compassion in people.
3. Getting people to choose reason instead of force for solving their differences.
Why? Because I choose to play the game of trying to make the world a better place. Such can be done in many ways. I prefer the most grand way.
Why? Because I live to create things. It's my idea of fun. It's how I prefer to spend my free time. Create this, create that. I wish I had a castle out back I was slowly building. But that would just be a small diversion as it would be less grand.
...the secret polemical heart. The overriding direction.
But the above is of course extremely vague. The ways to attempt to accomplish such tasks are endless.
...when you write of villains, the reader learns to recognize what a "villain" is and hopefully have such memories of what villains do ingrained in them so that they themselves don't later in life become such a person. In this way you reduce indifference. You reduce the use of force. Etc. Etc. So often I see people act awfully and I think of how they're practically a 2D bad guy and I wonder how they can be that. And I think (and it seems to be true) that usually they're the sort who never really got into that whole "reading thing."
The standard stories generally accomplish tasks 1, 2 and 3. There can then be further levels; where in order to take compassion, reason and the love of knowledge even further we have no choice but to learn to reject the social norms of this society...