Q:

What was the point (out of universe) of house-elves?

When I first read about house-elves in The Chamber of Secrets, I thought they were introduced as a very clear ethical artifact to teach children reading the story about slavery and forced work. The references and similarities with racism introduced by muggle born and "mudbloods" would then be extended to cover other ethical concerns.
However, during Goblet of Fire and further down the series the house-elves are depicted as actually wanting to serve and, with the exception Dobby, being unhappy when not allowed to do so. To me that basically counteracted the main ethical message to the children.
So my question is: Was there a point for introducing the house-elves into the story, or were they just a plot device to get the plot moving in the right direction?

A:

Like practically everything else in HP, it is part of the overall racism theme

Q. Your books have a theme of racism with the wizards oppressing other races and half­bloods. Do you think this has changed how people think when they read them?
JK Rowling: do not think I am pessimistic but I think I am realistic about how much you can change deeply entrenched prejudice, so my feeling would be that if someone were a committed racist, possibly Harry Potter is not going to be to have effect.
I would hope that it has made people think, I mean I do not write the books thinking what is my message for today, what is my moral, that is not how I set out to write a book at all. I am not trying to criticise or make speeches to you in any way, but at the same time, it would be great if the people thought about bullying behaviour or racism. The house elves is really for slavery, isn't it, the house elves are slaves, so that is an issue that I think we probably all feel strongly about enough in this room already.
Edinburgh "cub reporter" press conference, ITV

A:

I want to extend the good answer of ibid abit.
The phrase "entrenched prejudice" is important.   
If the house elves had not wanted to be slaves, the whole situation would have been so simplistic as to be almost babyish.
Adding a layer of entrenchment of the prejudice to include the house elves themselves challenges us to think "whoa, is it possible that a slave wants to be a slave?"
Thus it doesn't detract from the point of house elves as a device to illustrate and teach about the ethics of slavery, as implied by the question.  
Rather, it enhances it with real life questions and challenges.

A:

As ibid's quote shows, it seems that JKR's intended message is mostly clear.
But looking at just what we see in the books, there's other issues to consider. House elves are repeatedly shown possessing much stronger magic than the wizards - Dobby can teleport in and out of Hogwarts at will, he readily disarmed Bellatrix in a "duel" (though it could be argued that it only worked because she wouldn't ever imagine something like that would ever happen) and a similar case with Lucius in the Chamber of Secrets, Kreacher and Dobby easily overcame Fletcher etc. Chamber of Secrets in particular is full of impressive magic on  part of Dobby. So why are they serving in the first place, when they are so much stronger?
As far as I know, there is no canon answer. But we can consider a few possibilities:

There's simply too few house elves left. Even though they are individually very powerful, a rebellion would end badly.
They are used to the status quo, and see little benefit to freedom. They might even be outright afraid or undesiring of freedom. This was certainly the case for many slaves in our own history, so it would be an interesting reflection. In a few historical countries, slaves possessed much more physical power than their owners, and yet they kept being slaves (for way too many reasons to explore here :)). 
The magical contract between a house elf and it's family is binding, like the Unbreakable Vow, for example. At some point, the house elves agreed to be put into such a contract, and they could never break free on their own, "because magic". Until the owner voids the contract (like Lucius did), the elf simply cannot act against the owner (Dobby himself pushes this quite to the extreme, so either the binding is kind of vague, or there's many more complexities involved that weren't explored in the books). It does raise the question of why more owners didn't release their elves, but there's way too many plausible answers to that - for example, Dumbledore doesn't actually own the Hogwarts elves, most elves seem to be quite content with not being free (let's be honest, most people are quite content with giving away parts of their freedom - in a way, not having to care about some things gives you freedom as well).
Historically, there were plenty of slaves that had more real power than most freemen of the time (e.g. the master slave of a Roman senator), or even just power over the other slaves. This seems to apply to an extent (Kreacher seemed to be rather proud, and in a powerful position, due to his affiliation with the Black family), but probably doesn't apply widely enough. This may also be limited by the previously mentioned magical contract.

An interesting question is also where that binding contract came from. Maybe it was a result of a war as with the Goblins being forbidden from using wands? In that case, all the typical answers apply just fine - we've had plenty of historical precedent.
Maybe the house elves were created by a wizard at some point, specifically to be happy with servitude? If that's the case, we get into the uncomfortable territory of "when does a machine stop being a machine, and becomes a person/slave?". And what if that wizard adapted an existing creature (magical or not), rather than creating it from nothing? Is a pig with an artificially heightened intelligence, capable of abstract thought and speech a person? However, while this is a frequently explored and important ethical consideration, it most likely wasn't JKR's intention.
Overall, the parallels with historical slavery are quite clear, and probably quite enough :)

