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.