The Doctor, standing in front of the final wall, suddenly remembers what has been happening. He states that he always remembers at that point, all the previous times he's done this. He's so horrified and shattered that he hides under the console of his mental TARDIS and begs to please just get to lose for once, he can't keep doing this, he's as close to broken as he's ever been — and this is only after seven thousand years of repetition. He winds up continuing for over two billionnote thousand million counting on the long scale - the jump from hundreds of millions, to millions of millions, seems a little unlikely, and the universe itself wouldn't last that long, so there wouldn't be any stars left for him to estimate the number from years. How heavy did the weight of all those repetitions grow, and how much pain and exhaustion did he feel, every single time? Especially when you remember that once he finally escapes - he does not have the luxury of a bit of respite before remembering again. So he is still carrying all the fresh grief over Clara, and the knowledge that he'd been doing this over and over for billions of years. We see how desperate and sad he was after only 7,000 years - only Clara's memory calming him down. Imagine how unfettered and insane he must have been during his final realization after 4.5 billion years. The fact the Doctor is able to form coherent sentences and not be utterly insane by the time he arrives on Gallifrey is nothing less than remarkable. (That said, he might have had any number of iterations to "calm down" because he would have realized that he was getting very close to breaking through for hundreds if not thousands of years; his lack of hand injuries suggest his final iteration may have only needed one punch to break through.)
Every iteration of the Doctor has an identical experience, except for A) how far the stars have moved, and B) how deeply he's penetrated the crystal wall. Which of his billions of copies had it worse: the ones that saw no discernible change in the wall or stars yet, who never saw the paltry few skulls that'd so far accumulated and who'd believe themselves the first to come up with the idea of punching through ... and thus, to be condemning countless future copies to the same painful struggle, without even being sure it would work? The ones who could see visible evidence of progress, who'd know that they were just the latest iteration of a process ... and one that had billions of years still to go? The ones midway through, who could see evidence that inconceivably-many past and future Doctors had been and would be suffering their identical fate? Or the ones near the end, who could see the daylight at the end of the tunnel, but could tell there was still enough barrier left that thousands more Doctors would die in that nearly-completed passageway, on top of the billions who'd already been murdered there?
For that matter, the first time through, he wouldn't have known for sure that the crystal wall wouldn't re-set. In other words, there was a possibility that instead of a task that would take billions of years to complete, he was setting himself up for a task that would never finish, and he would simply keep looping through the same events forever.
Maybe the first few thousand iterations reasoned that if the ones later down the line saw no sign of progress in the wall, despite the stars having moved enough that there should be, this would break them out of that pointless loop, they'd leave a clue saying it won't work, and the rest would try something else.
In a way, this is as big a Wham Episode for the entire series as "Dark Water"/"Death In Heaven". In that season finale, we learned that virtually every character who's ever died on the show may potentially have wound up in Missy's Nethersphere. In this penultimate episode, we discovered that, for every single adventure that's been set between ~2015 and the last few centuries of the universe, one or more iterations of Twelve have been suffering and grieving and punching walls and dying simultaneously with whatever other trouble he or his fellow-Doctors have been getting into.
If only the Doctor had remembered what was going on slightly earlier, he could have made things so much easier for himself. Like, bring the spade so he could hit the wall with that instead of his fists, which would have been faster and much less painful. But because he never gets out of Room 12 between remembering and being killed, he is condemned to do things in roughly the least efficient way possible, spending billions of extra iterations on the task. All for the want of a bit of mental agility. Think how much he must blame himself for being so slow off the mark. Word of Godsaid that the earlier Doctors didn't even have a reason to look for Room 12 and lasted many years each before being killed by the Veil. Once he realized this, he started leaving himself clues, one of which (the buried paving slab) eventually survived through the resetting process. After that however, the loop went in a new direction, trapping him in Room 12 with the Veil and without the spade. Which was likely still faster than waiting years before landing a few hits on the wall as opposed to weeks at most.
Given that the Doctor is being observed, it's horrifying that no one tries to save the Doctor and stop this torture even as it becomes clear he is going insane and willingly undergoing it over and over. For that matter, depending on how time flows between the dial and the rest of the universe, the fact that no one seems to miss the Doctor or care enough to search for him is pretty awful. And we're supposed to be afraid his Tragic Dream will destroy the universe in the next episode? It Is Beyond Saving if this is how it treats one of its heroes!
The Doctor's hands when he picks up the Confession Dial don't seem to be bruised at all. Out-of-character, this was presumably so Capaldi wouldn't have to spend all of "Hell Bent" with bruise-makeup on his hands; in character, however, it implies that the last of his iterations to sacrifice himself was only one punch short of busting through the barrier. And the Veil didn't allow him even the half-second or so it would have taken to finish his eons-long struggle.
It's also possible that he intentionally ended the loop one punch early so he'd be able to use his hand after he broke out.
The Doctor arrives at the castle having seen Clara die in agony only minutes before. His grief is fresh and sharp and overwhelming. He spends a few weeks learning how the castle works and mapping it, and trying to cope with Clara's loss. And then he punches a wall, and crawls, and is burned up. And then he's back in the very freshest, sharpest grief. He spends the entire four and a half billion years losing her again, and again, and again. It's hard to think of a worse torture, even if they'd intended it!
Debatable depending on how prudish you are, the dry clothes the Doctor changes into belonged to his previous iteration. The very first one didn't get anything.
Try looking at all shots in the episode showing the Doctor's scrawl of the word "BIRD" in the sand. They're never written the same way. Because of the Amnesia Loop, the present version of the Doctor never really recreates the details each moment as he lived it the last time. After all, we can be quite sure he never really figured out the loop and the idea of punching through the Azbantium wall accurately the first few times.
This episode gives us a peek at the Doctor's Mental World, in which he holds metaphorical discussions with his own memory of Clara. Go back and re-watch him talking to himself in "Mummy on the Orient Express", and you'll realize that it was Tom Baker who was standing at the chalkboard inside his mental TARDIS that time. Also, re-watch Missy's account of how the Doctor'd survived a group of assassins, and consider that we now know how he'd come up with a sophisticated escape maneuver in about half a second: he popped into his mental TARDIS and told himself how he'd escaped.
It may seem strange that the Doctor has so much time to debate himself from within his MindTARDIS. (Even understanding that it's really just a metaphor for his thought processes.) Until you remember that it's still a TARDIS. He has as much time as he needs.
For years now, villains who've attempted a Breaking Speech on the Doctor have accused him of having the deaths of millions or billions on his conscience, thanks to the Time War and many, many other exploits. Ghastly though it is, this episode has finally given him the perfect comeback to such accusations of hypocrisy: yes, he does indeed have the blood of that many on his hands, but as of "Heaven Sent", the clear majority of those billions of deaths were his own.
Why does Clara keep facing away from the Doctor in his Mental World? It's not just a symbolic reminder that she's gone — it's because she was also facing away from him when she died. The Doctor is literally imagining the last time he saw Clara alive. And when she finally does turn around, the first thing his mental Clara does is stroke his face - the last thing she did for him before meeting her death.
It's telling that the portrait of Clara - which Word of God confirms was painted by the Doctor, not placed there by anyone - is not of Clara as she looked at the time of her death. In fact, the image of Clara comes from the Series 8 timeframe, before she started to become more like the Doctor. The Doctor is remembering Clara before she really started to change during her time with him. And she's smiling, something the Doctor says he'll want to remember of her.
Fridge Funny: All those fans who'd been outraged by the sonic sunglasses, and posted endless tweets or comments that they ought to be ruthlessly destroyed? Twelve puts them back in his pocket just before he starts punching the wall, and leaves them there right up until he pulls the lever. Which means that those much-lambasted specs have indeed been destroyed, as per fan request, hundreds of billions of times.
Everyone realizes that Clara becomes more Doctor-like over the course of her tenure as a companion, but every once in a while, an episode shows us that it works both ways. What did Clara do in "Name of the Doctor"? Create untold millions of Claras born to save the Doctor. What did the Doctor do in "Heaven Sent"? Create untold trillions of Doctors born to save and/or avenge Clara.
The Doctor would have been more truthful to pass on a message like "GET OUT VIA ROOM 12" or "GO TO ROOM 12", but he might not have trusted such a message. "I AM IN 12" on the other hand, hints at the presence of another person being in the castle, and after however many weeks or months the Doctor has spent learing how the castle works, mapping its levels, and finding the best way to avoid the Veil for the longest time, all of it alone, the Doctor will be drawn to the promise of some sort of company almost as much as to the chance to rescue someone trapped and/or confront those who trapped him.
This takes on a whole other slant when you factor in that Moffat reports in an interview that there was an "I AM IN 12" message on the back of Clara's portrait!
Moffat also reports that the first few incarnations to arrive at the castle lasted for years before learning enough to set up the clues, so they would be even more desperate for company, and probably couldn't think of any message more certain to lead themself to where they needed to go.