There are a few somewhat legitimate scientific explanations for why people might experience "ghosts," but they have to hold less to scientific rigor and provide a few assumptions that are more scientifically plausible, while still not being scientific fact. It's more like somewhat-intelligent people saying, "alright, fine, let's assume your experience was genuine, and try to find at some way to at least partially fit it into the realm of science."
All the same, there is no real explanation that provides any credibility to claims of people experiencing "ghosts." Most commonly, it is just a combination of explainable phenomenon compacted by hysterical mentalities. Or hallucinations, or hoaxes, or lies.
I'm not saying it's impossible that "ghosts" exist in some manner, by some means, I'm just saying that if they do, there is a rational explanation for why they do, although such a thing may escape current science.