The hat man is a common hallucination of a shadowy man with a wide brim hat experienced in psychosis. I know about it cause it's commonly reported by people who take too much dxm or people on multi-day no-sleep stimulant binges.
It's just a form of pareidolia, your brain just trying to make sense of dark shadows in your room in its forced twilight. It's pretty much a meme.
