system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5: Why do people start to hallucinate while they are sick or dying?

Context: A friend of our family was in the hospital for a very long time and also was in a coma for 3 months. While his wife was sitting next to his bed he kept starring to the wall. When she asked why he is doing it he told her   a person ("Death/Reaper") came in three times today and he told that person to go away since he is not ready to go yet. His wife started crying in the hallway and talked to his doctor. She told her that three people died the night before. I guess it's just a coincidence, but I keep hearing those stories from people I know and I also come across them on the internet. I am pretty sure many people just come up with the stories for the clicks, but not all of them are made up.

What is the explanation for this?
gpt
The term for this is delirium. Delirium is quite complex and is defined by confusion, changes in awareness and attention. There are many things that cause delirium some of them are direct injury to the brain (stroke, brain infections, etc). Other things (infections, liver disease, medications, prolonged ICU stays) have been known to cause delirium but we don’t exactly know why. Dementia and aging are definitely known risk factors for delirium because we lose our brain volume as we age.

There are some theories out there but it is all poorly understood. The best thing we have for it is treat the underlying cause (if there is one) or try and control symptoms. 

It’s a good question but unfortunately one we don’t have all the answers to.