The Harry Potter ghosts are mysterious creatures in the universe, but we have the answers to many questions about them
There is just so much to talk about Harry Potter and its multiverse — different tiers of canon include the books, movies, official websites, video games, to name a few. One aspect not discussed in detail is that of Spirits, who are often background fixtures in the story (playing important roles on very rare occasions.)
Ghosts are the most commonly observed ones, but several others have been featured include Boggarts, Poltergeists and Dementors. As it is with humans, not all spirits are evil, but not all of them are completely benign either, and most of them are more neutral than anything else.
The short answer to this is: technically yes, but the fact that ghosts tend to "haunt" a specific place symbolizes the deep affinity they had for that location whilst they were alive. This doesn't necessarily mean that they loiter around wherever they died, for instance, Helena Ravenclaw, the Grey Lady, is killed in Albania, but returns to Hogwarts to become the ghost of her former House.
This is in line with the standard understanding that ghosts exist because they are attached to something in the living world, even if it means "choosing a feeble imitation of life," as Nearly-headless Nick says.
The Dementors of Azkaban are officially categorized as non-beings, as they aren't exactly alive (and, by extension, cannot die.) Nobody is really sure how they came into existence, except that the island of Azkaban and its original inhabitant, the Dark Wizard, Ekrizdis, had something to do with it.
He spends his lifetime apparently abducting and experimenting on random sailors who happened to chance upon his vicinity, but when he dies, the Ministry of Magic discovers the hitherto unknown island and its demonic contents: a host of Dementors.
Ghosts in Harry Potter, as they are in most fictional universes, are composed of an enigmatic substance known as "Ectoplasm." This is a glue-y material that magic-users tend to hate as it simply gets in the way half the time, and ghosts are seemingly unable to stop secreting it all over the place for no reason.
Luckily, a simple Skurge spell is suggested to get rid of Ectoplasm, which has the convenient secondary effect of also getting rid of any pesky ghosts lurking in the area.
Sadly for ghosts, they are completely unable to sense most things in the world of the living, being a vague approximation of what they used to be (an imprint of reality, if you will.) As such, they experience no personal growth either, holding on to whatever grudges or miseries they had while they were alive。
For example, Nick is constantly whining about his quasi-decapitation, regardless that it occurred over five centuries ago. One thing ghosts can supposedly taste, though, is putrefying food, because of its high level of rancidity and possibly because it can be considered not entirely dead.
Not all the time, but they certainly do have a calling sign of sorts — for example, whenever a ghost phases through an object, it doesn't change the object as long as it's a solid; however, fire develops a temporary blue shade when they "interact with it," and also "create disturbances in water."
As Harry himself has endured, it feels like being "plunged into ice-cold water" when a ghost passes through a human body (and their general proximity results in a reduction in ambient temperature.)
Although they are all known by name (and a brief backstory), the Hogwarts House ghosts are quite a fascinating bunch. Sir Nicholas De Mimsy-Porpington of Gryffindor is executed for a silly cosmetic magic error and the Fat Friar of Hufflepuff is eliminated by paranoid clergymen.
The other two: the Grey Lady of Ravenclaw is murdered by her jealous admirer, and this admirer happens to be the Bloody Baron of Slytherin, who immediately commits suicide after realizing what he had done. How they all hang out at the same place without brewing conflict is anyone's guess.
An interesting detail about ghosts is that non-magic folk do not become one when they die, nor are they able to actually perceive their presence. Aside from the Skurge, the Ministry of Magic has been shown to have some level of authority over ghostly activities, which is ensured by the Department for the Regulation and Control of Magical Creatures.
The existence of a Boggart is proven by its manifestation of fear, as it takes whatever form is most terrifying to the person standing before it. Why it does this is unclear — perhaps they thrive off their victim's terror, or maybe they are just irksome creatures.
This is a rather complex conundrum: on one hand, Nick gently explains to Harry that Sirius would never be coming back because he would have "gone on," while on the other, is it really possible for something to remain static forever? Ghosts have what they call "unfinished business," so does this mean that they are freed of their condition if said business is finished?
Consider Lord Voldemort, who gets himself trapped inside a horrifying baby-monster because of all his soul-mutilation. He may have been a super evil Dark Lord, but punishing him for eternity without a single chance for reprieve doesn't really make moral sense. On the opposite end of the scale, the History of Magic Professor, Cuthbert Binns, wouldn't move on even if he could.
Peeves, who inexplicably doesn't appear as comic relief in the movies, is a poltergeist, but not a normal one (as almost all others are not visible to people.) This devious fiend takes great pleasure in causing havoc at Hogwarts, but is not evicted by Dumbledore because he isn't that much of a disruption, to be honest.
It's said that he has been at the Castle ever since it was built, which implies that his character is an intrinsic part of the school, as much as anything that the four Founders have done.