Harry and Dumbledore are in Dumbledore's office after Harry has defeated the Basilisk in the Chamber of Secrets. Lucius Malfoy bursts in accompanied by Dobby. Is there an explanation as to why Dobby is with Lucius at this time? It seems strange that Dobby is with Lucius at this time, when on other occasions in the book Dobby isn't with him.
The reason is that Dobby was polishing his shoes while Malfoy had to leave in a hurry
Dobby probably had no option but to apparate with him
“Good evening, Lucius,” said Dumbledore pleasantly. Mr. Malfoy almost knocked Harry over as he swept into the room. Dobby went scurrying in after him, crouching at the hem of his cloak, a look of abject terror on his face. The elf was carrying a stained rag with which he was attempting to finish cleaning Mr. Malfoys shoes. Apparently Mr. Malfoy had set out in a great hurry, for not only were his shoes half-polished, but his usually sleek hair was disheveled. Ignoring the elf bobbing apologetically around his ankles, he fixed his cold eyes upon Dumbledore.
Thanks to Mac Cooper for digging up the quotes
There was absolutely no reason for this. Just for the sake of the plot. Wizards don't usually walk around with their house elves. The only other time we see a house elf outside the family house is when Winky was at the Quidditch World Cup, and that was due to the fact that she was Barty Crouch, Jr's chaperone. I am not counting Kreature's disappearances from Grimmauld Place.