Because the activities of a few cells when awake lose the control and regulation of the whole cerebral cortex, some fragments of memory become active without restraint, which may show strange dreams different from normal psychological activities. When you come into contact with a dead person before going to bed, or there is a dead person in the story, it will become a stereotype and probably appear in your dream.
Often dreaming of dead people means that you are weak and healthy, so you are easily disturbed by the information of ghosts and gods in your dreams, which is also commonly known as "eight-character weakness" If this happens frequently, you should seek psychological assistance from a psychologist.