I am adding another answer, because I have found another source that explains the Doctor's role as Merlin, but one which is inconsistent with the previous answer (in spite of some similarities).
Another version of the Doctor's stint as Merlin is described in the short story "One Fateful Knight," by Peter David. This version was published in a Big Finish anthology in 2008 and so was explicitly written to fit into the continuity established in "Battlefield" in 1989.
As in "The Creation of Camelot," the Doctor (the Eighth this time) arrives on the scene when another Time Lord has already taken on the role of Merlin and is trying to interfere with Earth history.
The plot summary, per the TARDIS wikia:
When the Doctor lands in a castle, he is immediately asked to help deliver a baby. It turns out the mother is Igerna, who claims the baby's father is her husband, Gorlois, who died on the battlefield the night the baby was conceived. When the baby is delivered, Igerna names him Arthur. The Doctor calls himself "Merlin".
The Doctor later encounters another Time Lord who has been calling himself Merlin. This Merlin intends to disrupt the normal timelines by supplying advanced weapons to primitive cultures. The Doctor plans to stop him and tracks his TARDIS.
The Doctor loses "Merlin" but ends up overhearing Morgaine and Arthur. Morgaine gives Arthur a sword and leaves; after which the Doctor meets up with Arthur.
Much later, Arthur and his men are fighting Mordred and his men, who have advanced technology. Mordred taunts Arthur, implying Arthur's loyal follower Ancelyn is having an affair with Arthur's wife Guinevere. Morgaine arrives and tries to kill Arthur, but the Doctor shows up in the nick of time and materialises the TARDIS around Morgaine.
The Doctor strands Morgaine and returns to the battle, where Mordred has been captured. The Doctor promises Arthur that he will chat with the queen about the rumours spread by Mordred.
However, the Doctor materialises within the other "Merlin's" TARDIS. "Merlin" goes to Guinevere and warns her that Arthur is dead and Mordred is coming to claim her. She readies a crossbow and kills the man who enters — who happens to be Arthur.
The Doctor arrives but he is too late to save Arthur. The other Merlin gets caught by Morgaine.
The Doctor buries Arthur in Lake Vortigern and leaves a message for his past self.