The short answer is that ghosts/ poltergeists can be shades of the dead, spirits or thought forms.
Now for the explanation:
When people experience strong, often negative, emotions for a longtime, those emotions can be accidentally projected into a thought forms. These thought forms can go on to become poltergeists ( you see this stuff occasionally in houses where someone was abused for a long period of time: the whole place feels sad and the air is often very heavy ).
The spirits don’t really need too much explanation. Spirits can be attracted to an area, or welcomed in etc. When their influence is significant enough, they can start to interact with the physical world around them.
As for shades of the dead, the answer is going to depend on how you view the human soul. As in, whether you feel humans posses an immortal soul that will persist forever, or if you believe humans draw in energy from the world around us and build up a soul over time ( a mortal soul that slowly dissipates upon death ). Personally, I’ll be answering from the second view point.
When a person dies, their soul leaves the body and begins the process of fading away. During this process, it can continue to carry the will of the dead person, in much the same way energy channelled in a ritual carries your will forward into the world. In this way, the human ghost is similar to the poltergeist. If the person had a strong enough will to exist, you can see some spiritual activity. Again, it happens most often with negative energies, but can also arise when someone was very spiritually powerful or simply felt they had more to do before they died.
I wouldn’t listen to what Islam teaches about anything, it’s just a mishmash of stories that were popular during Mohammed’s time and teachings that benefited Mohammed’s rise to power.