This thread is in danger of being hijacked by people who think it’s about whether ghosts exist outside of the imagination, or about James Randi’s work. It is about neither.
I’ve met enough people who believe in ghosts (including some professional psychics, mediums and ghost-hunters) to have heard a range of responses to the question in the OP.
Some say that when a ghost appears, what is perceived is a fusion of the ghost’s actual presence and the perceiver’s own expectations, sensibilities and ability to comprehend what they are perceiving. So, for example, ghosts are usually perceived as clothed because we normally see people clothed, and they are often seen wearing clothing appropriate to a particular era in history because that’s appropriate to our sense of history and the passage of time.
Some point out that the vast majority of us, when we choose to manifest ourselves towards others, choose to wear clothes (e.g. it’s happened at every Dopefest I’ve been to). So why should we be surprised when ghosts choose to do the same?
Some say that what we perceive as clothing is really symbolic and connotative, but it’s either the only way or the easiest way for our mortal minds down here on the earthly plane to assimilate the signs and symbols that are being conveyed. In other words, it’s a form of spiritual short-hand and symbolic imagery. What’s a good way for me to show you that I was an Edwardian bride? Answer: to manifest something you will understand as symbolic of, or connotative of, an Edwardian bride… such as Edwardian bridal wear.
And so on. It is possible to invent as many theoretical answers as you like, since any answer can be right, any answer is as good as any other and none can be tested.
Personally, I believe the perception of ghosts is a real event, which is why reports exist in every culture and in every era. But all the evidence we have suggests the ghost itself exists behind the eye (in the mind) rather than in front of the eye (in the real world). The perception is real, and it may be triggered in part by real things (atmosphere, surroundings, shock, surprise, emotive events), but the percept is not distinguishable from something merely imagined.