How did the Third know Yamato's name?
In - universe reason : Tsunade did gave him the name Yamato but it was never implied that Anbu codename can't be reused. Maybe she used his old name and third knows it.

Out-of Universe reason : Kishimoto must have forgot it due to complex nature of story, this kind of mistake are not that uncommon in any series and anime just followed manga and kept it that way.