This continues the account of what happened when Jesus was born as the King of the Jews.
But when he heard
"But when Joseph heard"
his father Herod
This is Archelaus' father.
he was afraid to go there
The "he" refers to Joseph.
he would be called a Nazarene
The "he" refers to Jesus.