Julian Jaynes' book is of course relevant. [1]
Further to that, I've read on several occasions about lone survivors of disasters who report encountering a person who wasn't there who helped them to survive.
The most common I've encountered is the stereotypical tale of "mountain madness" [2] where an injured or lost climber receives help or guidance from an imaginary being (who presumably seemed quite real to them during their escape from peril).
Literature, fiction and cinema are all full of similar tales (not all in mountain scenarios) and so I expect that this "ability" is part of being human.
There would be an evolutionary advantage to be had if the brain was able to access some "hidden partition" containing recovery instructions during times of extreme stress.
[1] https://en.wikipedia.org/wiki/Bicameralism_(psychology)
[2] https://consumer.healthday.com/fitness-information-14/climbi...
Edit: better [2]: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6088769/