Because the Doctor is a time traveller, it's possible for him to meet past (or future) versions of himself. This is what's known as "crossing his own time stream". Although possible, it's illegal. (It's contrary to the First Law of Time, as pointed out by the Time Lords in "The Three Doctors", when they themselves arranged for the Doctor to do it.)
It's forbidden because it's dangerous & can easily lead to temporal paradoxes. As a protection against such paradoxes, the earlier versions involved in such a meeting lose all (or most) of their memory of the events, once the time stream crossing comes to an end. That was pointed out in the episode by the "War Doctor" & the Eleventh Doctor, just before they parted:
- WAR DOCTOR: I won't remember this, will I?
- ELEVENTH DOCTOR: The time streams are out of sync. You can't retain it, no.
In this story, the various versions of the Doctor met because the Moment arranged for it to happen, even letting them pass through the time lock that ought to have kept them from re-entering the Last Great Time War.
Any time traveller could potentially cross his/her own time stream & several others have done so. The effects vary, depending on what happens when they meet. In the case of the Brigadier in "Mawdryn Undead", for example, the effects were quite drastic & caused him to suffer a major loss of memory, because the two versions of himself actually made physical contact, resulting in a violent discharge of temporal energy.