The Veil was a terrifying creature drawn from the Doctor’s own nightmares.
Trapped in a clockwork castle by an unknown enemy and with no means of escape, the Doctor was confronted by the Veil, a limping and disfigured creature shrouded by a sheet and swarming with flies. This ghastly entity reminded the Doctor of a dead body that he had seen and been scared by as a child.
…When too late you rise to go, you will notice a second shadow next to yours. Your life will then be over…The Doctor
Instinctively feeling that he had to get away from the Veil, the Doctor quickly learnt that wherever he went and whichever path he chose, the Veil would always follow at exactly the same, slow pace, never stopping to rest.
When the Veil inevitably got close to the Doctor, arms outstretched, he admitted that he was genuinely scared. This caused the Veil to be momentarily frozen and the castle to alter its configuration to allow the Doctor to escape. This was the evidence which the Time Lord needed to ultimately deduce that the Veil was specifically designed to respond to his confession of unspoken truths. Only the deepest, darkest secrets would satisfy the Veil and prevent it from killing the Doctor.
Realising that he had been purposefully trapped in a prison specifically designed to torture him, it wasn’t long before the Doctor concluded that the secret which his captors wished him to confess above all else was simple: the reason he had run from Gallifrey centuries before. The Veil was an instrument to have the Doctor confess the true identity, should he know it, of the prophesised Hybrid.
Considering the information to be too dangerous, the Doctor was unwilling to let all that he knew about the Hybrid fall into the hands of anyone and was forced to look for another way to escape his prison. When the Doctor finally gained access to Room 12, he found a wall made of solid azbantium, 400 times harder than diamond, marked with the word ‘Home’, which he assumed to be the only way out.
Rather than any further confessions to the Veil, the Doctor began to punch the wall, and allowed the Veil to fatally injure him, before hauling his body back to the teleport room to reset the technology and bring an identical copy of himself to the castle. The only clue to his escape was the word ‘Bird’, written in the sand by the Doctor, to remind himself of a story about the meaning of infinity. With this, the Doctor knew how long it was going to take him to escape from the Veil.
The Doctor repeated this exact process over four billion years, each time striking the wall, until the wall shattered and he was able to go free.
After evading the Veil, the Doctor discovered he had been trapped inside his own confession dial by the Time Lords in an attempt to uncover everything he knew about the Hybrid. He had finally been released on his home planet, Gallifrey, at the very ends of the universe.