According to studies on everyone's favorite test subject—college students—the answer is: no more than 7 days.
Studies on human subjects are rare — in part because most
modern universities would never consent to them — but in 1951
researchers at McGill University paid a group of male graduate
students to stay in small chambers equipped with only a bed for an
experiment on sensory deprivation. They could leave to use the
bathroom, but that’s all. They wore goggles and earphones to limit
their sense of sight and hearing, and gloves to limit their sense of
touch. The plan was to observe students for six weeks, but not one
lasted more than seven days. Nearly every student lost the ability “to
think clearly about anything for any length of time,” while several
others began to suffer hallucinations. “One man could see nothing but
dogs,” wrote one of the study’s collaborators, “another nothing but
eyeglasses of various types, and so on.”
While this study is problematic due to questions about the ethics of McGill researchers at the time, it is widely cited. Other studies about social isolation (solitary confinement) with or without sensory deprivation (in both humans and animals) come to similar conclusions about mental state (though not necessarily hallucinations).
This wasn't being trapped underground, but it seems like a reasonable approximation. The difference is that the graduate students knew they were safe and getting out. Your character doesn't know if he'll ever be rescued and is likely to just give up after a while.
Now, if your character were trapped with a group of people, the answer is months. A group of Chilean miners were trapped underground for 2 months, with the first part of that being without anyone knowing if they were alive and without any evidence they might be rescued. After that they had communication with the outside world and a conduit for food and supplies, though only a small hope of a successful rescue. After their amazing rescue (every one of them survived), they had psychological issues, but not insurmountable ones.
In another case, a man who was trapped underwater for 3 days but survived continues to have nightmares and has vowed never to return to the ocean. He was in a shipwreck and was rescued by divers working to recover bodies from the wreck. He had no contact with other people, no realistic hope of rescue, no light (after his flashlights died), almost no food or water (just a soda), and horrible conditions.
Being alone, being in the dark, not knowing if rescue is possible, those are all things that worsen the effect on the mind.