This is ironic because of the way that Gandalf presents it. Tongue in cheek he is playfully asking the hobbits about the phrase. For example he says: "What do you mean?" Gandalf said. "Do you wish me a good morning, or mean that it is a good morning whether I want it not; or that you feel good this morning; or that it is morning to be good on?"
Later he says: What a lot of things you do use Good morning for!" said Gandalf. "Now you mean that you want to get rid of me, and that it won't be good till I move off."