In Harry Potter and the Sorcerer's Stone, several ghosts are shown e.g Nearly Headless Nick, Moaning Myrtlee etc, but later it is revealed to Harry that dead can not be brought back to life. Then how come these ghosts exist? Why didn't James and Lily became ghosts as well? Kindly help.
In the book Harry Potter and the Order of the Phoenix, there is an exchange between Harry and the ghost Nearly Headless Nick (played by John Cleese in the films) which explains why some wizards return as ghosts and others do not:
"Wizards can leave an imprint of themselves upon the earth, to walk palely where their living selves once trod", said Nick miserably. "But very few wizards choose that path."
"Why not?", said Harry. "Anyway - it doesn’t matter - he won’t care if it’s unusual, he’ll come back, I know he will!" [...]
"He will not come back", repeated Nick. "He will have... gone on."
"I was afraid of death", said Nick softly. "I chose to remain behind. I sometimes wonder whether I oughtn’t to have... well, that is neither here nor there... in fact, I am neither here nor there..."
He gave a small sad chuckle. "I know nothing of the secrets of death, Harry, for I chose my feeble imitation of life instead."
In short, a ghost is an imprint of the soul that wizards leave behind because they were afraid of the death (of, rather, of "going on" after it).
I wouldn't expect Harry's parents to fall into the "fearing death" category.
I don't think anyone could really answer this question. However, there are two key-points someone must consider:
A person can never truly grasp the idea of "death". Neither can we. Nearly-Headless Nick said he was rather afraid of it and thus chose not to leave, which makes him seem kind of a coward. Now, there is no doubt that both Potter's parents and Dumbledore were braver and had more courage than him and they all chose not to come back, so maybe the first keypoint is courage.
Lily and James Potter's death is a major contributor in the plot of the books. Without their death, there would be no Chosen One nor a conflict really, so it is crucial that they die and not return.