Take the case of pilot Frank Smythe who was alone on Mount Everest. He was overcome with a feeling of weariness and hopelessness. He decided to eat and grabbed for a slab of Kendal mint cake he had in his pocket. What was weird, is how he remembered cutting the cake into 2 pieces, one for him and one for his “companion”.
He says ’I had a strong feeling that I was accompanied by a second person. The feeling was so strong that it completely eliminated all loneliness’
When he made it back to base camp, he was too scared to talk about it for for fear of ridicule.
You can read more cases here
Some scientific explanations is that it’s a hallucination as a coping mechanism or an example of bicameralism (the hypothesis that the human mind is divided into two: one that speaks and the other that listens.)