This question occurred to me because of The Steampunk Bible. One of the essays contained therein was "Blowing Off Steam" by Catherynne M. Valente, and in it, she argued that a work must accurately portray the horrors of the Victorian era (unsafe factory conditions, terrifying societal change spurred on by technology) in order to be truly steampunk. "If you want Victoria in your coat pocket," she writes, "if you want the world that comes with her, all that possibility, all that terrible, arrogant, gorgeous technology, take it all, make it true, be honest and ruthless with it, or you're just gluing gears to your fingers and telling everyone you're a choo-choo train."
You can agree with her or not, but her objections to much of modern steampunk raise an important question. Steampunk might not exist without steam and children slaving away in dangerous factories, but by the same token, cyberpunk might not exist without futuristic sweatshops where people are paid pennies a day to make bionic implants. Pseudo-medieval fantasy can't exist without peasants and the feudal system. As we've known ever since Fritz Lang filmed Metropolis, Utopian societies generally require someone living in non-Utopian conditions to make them happen.
Is a writer of the fantastic under any obligation to portray this?
I've always disliked the idea that a writer "has" to write with a moral in mind- or that a writer "has" to do anything, for that matter. I don't think it's wrong to read or write escapist fiction, and to not want to be bothered by grim and dirty realities. I've also seen grittiness taken too far; one of my biggest problems with the Warhammer 40k universe is that the evils of all the factions are so exaggerated that it becomes hard for me to care about anyone winning at all. And I think we've all read enough preachy science fiction, or at least seen a bad episode of The Twilight Zone, to know how painful it can be trying to enjoy something that wants to lecture first, entertain second.
However, this doesn't mean I entirely disagree with the notion of sci-fi having a conscience. Harshly put as it was, Ms. Valente's point still stands; we can't fully appreciate the glamour of a setting unless we get a little bit of the grit. Any setting, whether historical or imaginary, can have the capacity for both horror and beauty, and the two often go hand in hand.
I don't think fiction has any obligations, but I do think that fiction is better when it is informed by the context in which it takes place. When the author knows what problems their characters will face in their day to day lives, and what problems go unseen by them on a regular basis, that provides for a much richer text. Discworld wouldn't be half as fun if the city of Ankh-Morpork wasn't a filthy mixture of medieval, Victorian, and modern urban blight, and the anachronistic blast that is Samurai Champloo wouldn't be as interesting to watch if one of the protagonists being an illiterate peasant never became an issue.
In short, I don't think you have to zero in on a society's problems in order to write a good story. But if you want to portray a rich and enveloping universe, you need to be aware that they exist.