On the most basic level, this title, "The Haunted Palace" lets you know what the central focus of the poem is, the main image it deals with. Although, we think it's important that the palace doesn't start out being haunted. So, the title is doing a little bit of foreshadowing. In a way, a title like this one subtly prepares you for what's going to come at the end of the poem. Think of it like a teaser trailer for a new movie. When you go to watch that movie, you have an idea of what's coming, a few images from when things really get going. Even if there are no giant robots at the beginning of a Transformers movie, for example, you know they'll show up eventually.
In this case, you go into this poem with the spooky mental image of a haunted palace already set in your mind. Even if the haunting doesn't happen until pretty far into the poem (line 33) you know it's on its way, because you read the title. Even when you're reading about cheerful, peaceful times, you know they can't last. Bummer.