In the beginning of Harry Potter and Chamber of Secrets, Dobby alerted Harry about a secret plan which his master had.
Why did Dobby cheat his master?
Science Fiction & Fantasy Stack Exchange is a question and answer site for science fiction and fantasy enthusiasts. It only takes a minute to sign up.Sign up to join this community
"Why did Dobby cheat his master?"
Because Proletariat has Nothing To Lose But Their Chains (Karl Marx (c))
Dobby was NOT on the side of his master - he was a "freedom minded" house-elf, didn't like that house-elves were subjugated to wizards (as evidenced by his post-freeing thoughts, speech and behavior); didn't like Dark wizards, and knew that DE's winning would make house-elves lives worse. So if he could do something to prevent that from happening, he would.
He admired Harry potter precisely for his thwarting of Voldemort:
“Harry Potter asks if he can help Dobby… Dobby has heard of your greatness, sir, but of your goodness, Dobby never knew…”
“Harry Potter is humble and modest,” said Dobby reverently, his orb-like eyes aglow. “Harry Potter speaks not of his triumph over He-Who-Must-Not-Be-Named —”
He also didn't like Malfoys specifically:
“Offend Dobby!” choked the elf. “Dobby has never been asked to sit down by a wizard — like an equal —”
“You can’t have met many decent wizards,” said Harry, trying to cheer him up. Dobby shook his head. Then, without warning, he leapt up and started banging his head furiously on the window, shouting, “Bad Dobby! Bad Dobby!”
“Dobby had to punish himself, sir,” said the elf, who had gone slightly cross-eyed. “Dobby almost spoke ill of his family, sir…”
Meaning, he HAD ill thinks to speak of them in response to Harry's remarks.
I'm assuming that you are asking why he went against Malfoy's will, NOT why he assumed that helping Harry Potter would achieve his goal of thwarting DEs. If you were asking about the latter please clarify your question.
I think this is going to end up being slightly speculative, but I'll take a shot at answering this. As I mentioned in a comment, saying that Dobby betrayed his master's plans to Harry isn't entirely correct; Dobby didn't tell Harry what Lucius Malfoy was planning, only that Harry would be in danger if he returned to Hogwarts. So, why would he do that?
Harry, and the reader, learns early on in the first book that he is, within the wizarding world, incredibly famous. Not only is he famous, but he's famous for one of the most important events in recent history - the defeat of Voldemort. This may be enough for Dobby to want to keep him alive, and therefore warn him when he's going to be putting himself in an extremely dangerous situation.
Lucius Malfoy was one of Voldemort's most loyal and trusted followers. Important enough to have been entrusted with one of his horcruxes, even if he didn't know that's what it was (Voldemort isn't going to share that no matter how much he trusts somebody). We can safely assume, I think, that he would have also been trusted with Voldemort's secrets, such as what he knew of the prophecy concerning Harry and Voldemort.
Given what we know about the Malfoys attitude towards House elves, they're not likely to take much notice of Dobby if he's present while they're discussing important things, such as plans to re-open the Chamber of Secrets or the aforementioned prophecy. Sure, this is speculation, but I don't think it's unreasonable to think that Dobby would have knowledge of a lot of these things.
If we work on the assumption that Dobby knows about the prophecy, then he'll know that Harry is not only important for what he did as a baby, but what he'll do in the future. That seems like a very good reason to want to keep him safe and away from harm to me. Especially if you consider that the lives of House elves are likely to get much worse if Voldemort was to return and take control.
I think stating that Dobby cheated his master is assuming more than we can know. The book goes to lengths to point out that Dobby might have been sent to Harry to keep him out of school. Perhaps Draco sent Dobby to the school? I've read the book many times, and were I to assume that Dobby did come to warn Harry to keep him safe, he did so without his masters knowing. Much like Kreacher in "The Order of the Phoenix" who leaves Grimauld Place to talk to Bellatrix and Narcissa, it appears that house elves are not forbidden to leave their homes. It seems they can leave. However, it was stated that Kreacher was only able to leave after Sirius told him to get out, meaning get out of the room. Thus, we have to ask (1) whether Dobby was sent by the Malfoys to keep Harry from Hogwarts, or whether he was actually there to help warn Harry; and (2) how much did Dobby know about what was going to happen. It's true that the Malfoys only knew that the book would open the Chamber of Secrets, not that it was a horcrux. Thus, we can assume that at most, Dobby knew that the book would open the Chamber of Secrets. If he knew that, he could not know specifically what would happen. He must have warned Harry simply based on the chance that Harry could be killed when the Chamber was opened. I think, thus, that he knew of Harry and wanted to keep him safe, and thought that keeping him at home would keep him alive.
In Book 2 Fred said House Elves weren't allowed to use magic without their Master's permission and he reckoned that Dobby had been sent to stop Harry from coming back to Hogwarts as some sort of joke. As previously stated, in Book 5 Kreacher was only able to leave after Sirius told him to get out. It would appear that Draco, upon hearing of his Father's plans, sent Dobby to "warn" Harry Potter. He did not his share this "joke" with his Father, especially after Ron told Draco "Bet you're surprised to see Harry here?" in the book store. Draco would have worried more about keeping the secret of a failure that would again disappoint his Father, rather than confessing he had given Dobby an (unintentional open-ended!) order to warn Harry Potter.