Harry's Parents:
* They were murdered with the Killing Curse: The Killing Curse, also known as Avada Kedavra, is a particularly powerful dark magic spell that rips the soul from the body. This leaves no chance for the soul to linger and become a ghost.
* Their deaths were traumatic: The nature of their deaths, being murdered by Voldemort, was so violent and traumatic that their souls likely scattered, unable to stay tethered to the mortal world.
Cedric Diggory:
* His death was caused by a curse: Cedric's death was also violent, but caused by a curse rather than the Killing Curse. While curses can be fatal, they don't always have the same soul-severing effect as the Killing Curse.
* He was a victim of circumstance: Cedric was caught in the crossfire of a larger battle, and his death was not targeted by a specific dark magic intent to destroy his soul.
Ghosts and Their Formation:
* Attachment to the world: To become a ghost, a soul needs to have a strong attachment to the mortal world, a powerful reason to linger. This could be a desire for revenge, unfinished business, or a deep love for a place or person.
* Strong emotions: Often, strong emotions like anger, grief, or love are the catalyst for a soul remaining in the world as a ghost.
In the case of Harry's parents and Cedric, their deaths were likely too sudden and traumatic to allow for these conditions. They were snatched away abruptly, with little time for contemplation or a desire to remain.
It's important to note: The Harry Potter series doesn't explicitly state the specific reasons why they didn't become ghosts. However, the explanations above align with the established rules about ghosts and the nature of their deaths.