From my own experience, it seems that a toddler doesn't have a strong understanding of what a ghost is supposed to be (the spirit of a dead person). Rather, it's a term that can be applied to "something that scares me" -- picked up by hearing adults (or other children) use the word while talking about being scared. If a teacher mentions she is afraid of the dark because of a ghost in the room, a toddler can pick up on that very easily.
When we were visiting family while work was being done on their roof, the shadows of the workmen could be seen on the nearby buildings (as well as random noises from the construction). My tween daughter told her toddler brother that they were scary ghosts. Rather than the game of pretend she expected, he got very scared and started hiding under the couches "from the scary ghost." She'd given him a distinct term to use to personify the anxiety he experienced from unpredictable loud sounds and unnatural shadows.
At first I tried pointing out that ghosts aren't real. However, he could simply point at the moving shadows to "prove" to me that there were, obviously, ghosts around the building (and did so in an increasingly frustrated state, presumably wondering why I pretended to not see the very obvious shadow-ghosts).
Instead, I made a game out of it. I'd say "Aaaah, it's a ghost!" and gasp and point at something. He would jump, and stare at where I was pointing. Then I'd say, "Oh, no, it's just the cat" (or "the couch", "the ceiling fan", "Mommy" -- or, eventually, "the shadows of a worker on the roof"). We played for a few minutes, then started doing something else, but I came back to this game randomly over the next few days. When it was mixed into play, it helped him relax and even take the lead on "scaring" me with ghosts that he then explained were really Uncle John, a fuzzy pillow, or my purse.
- It showed that it's easy to be mistaken about what you're seeing; a glimpse of a moving cat might look unnatural or ghostly at first, but on second look it's clearly a familiar pet.
- It's OK to be scared at first, as long as you take a moment to calm down, think about what you're actually seeing, and then even laugh about your mistake afterwards.
- A "ghost" can be easily explained as an actual object. Even in a dark room, once we turn on the lights we can see that spooky shape was actually just a favorite toy, or a familiar lamp.
- It can be fun to be a little bit scared by something we know is imaginary, particularly when done in a safe space (with a parent) and followed up quickly by a reassurance that everything is fine.