The angel tells Joseph to name the child Jesus Matthew 1:21. The reason given is that "he will save his people from their sins" Matthew 1:21.
In Matthew 1:20–21, Joseph is rethinking his situation when a divine messenger appears in a dream and addresses him with both personal and family-line language. The message tells Joseph not to fear bringing Mary into his home as his wife, because her pregnancy has a divine source. These verses come in Matthew’s opening narrative about Jesus’ origins, immediately after the genealogy (1:1–17) and the report that Mary is pregnant before living together with Joseph (1:18–19). Joseph’s initial plan in 1:19 sets up the tension: he intends to end the relationship quietly.
Matthew presents Joseph as facing a crisis and then receiving authoritative guidance through a dream: an angel tells him not to fear bringing Mary home as his wife, because the pregnancy has a divine origin ("from the Holy Spirit").
A careful answer keeps the immediate passage, the book's argument, and the whole-Bible storyline together, so the question is answered in context instead of as a detached idea.
Start with Matthew 1:21, then read the surrounding section so the answer stays connected to the passage's flow.
21She shall bring forth a son. You shall call his name JESUS, for it is he who shall save his people from their sins."