"A period of forty years separates the death of Jesus from the writing of the first gospel. History offers us little direct evidence about the events of this period, but it does suggest that the early Christians were engaged in one of the most basic of human activities: story-telling. In the words of Mike White, "It appears that between the death of Jesus and the writing of the first gospel,
Mark, that they clearly are telling stories. They're passing on the tradition of what happened to Jesus, what he stood for and what he did, orally, by telling it and retelling it. And in the process they are defining Jesus for themselves."
These shared memories, passed along by word of mouth, are known as
"oral tradition." They included stories of Jesus' miracles and healings, his parables and teachings, and his death. Eventually some stories were written down. The first written documents probably included an account of the
death of Jesus and a collection of sayings attributed to him.
Then, in about the year 70, the evangelist known as
Mark wrote the first "gospel" -- the words mean "good news" about Jesus. We will never know the writer's real identity, or even if his name was Mark, since it was common practice in the ancient world to attribute written works to famous people. But we do know that it was Mark's genius to first to commit the story of Jesus to writing, and thereby inaugurated the gospel tradition.
"The gospels are very peculiar types of literature. They're not biographies," says Prof. Paula Fredriksen, "they are a kind of religious advertisement. What they do is proclaim their individual author's interpretation of the Christian message through the device of using Jesus of Nazareth as a spokesperson for the evangelists' position."
About 15 years after Mark, in about the year 85 CE, the author known as
Matthew composed his work, drawing on a variety of sources, including Mark and from a collection of sayings that scholars later called
"Q", for Quelle, meaning source. The
Gospel of Luke was written about fifteen years later, between 85 and 95. Scholars refer to these three gospels as the "synoptic gospels", because they "see" things in the same way. The
Gospel of John, sometimes called "the spiritual gospel," was probably composed between 90 and 100 CE. Its style and presentation clearly set it apart from the other three.
Each of the four gospels depicts Jesus in a different way. These characterizations reflect the past experiences and the particular circumstances of their authors' communities. The historical evidence suggests that Mark wrote for a community deeply affected by the failure of the First Jewish Revolt against Rome. Matthew wrote for a Jewish community in conflict with the Pharisaic Judaism that dominated Jewish life in the postwar period. Luke wrote for a predominately Gentile audience eager to demonstrate that Christian beliefs in no way conflicted with their ability to serve as a good citizen of the Empire."----
https://www.pbs.org/wgbh/pages/frontline/shows/religion/story/mmfour.html#:~:text=About 15 years after Mark,, for Quelle, meaning source.
It's unlikely that Matthew deliberately made up certain details of Jesus' life. Rather he was just recording (or perhaps cherrypicking?) details and stories that were passed down orally over the decades since Jesus' death, which likely included many legendary and fictional details that supported the belief in the divinity of Jesus. It doesn't take long for stories passed down by word of mouth to acquire things that never happened and are simply not true. One can see this by the many apocryphal writings about Jesus that were being circulated in the 1st century and were eventually rejected by the Church from the New Testament canon:
https://en.wikipedia.org/wiki/New_Testament_apocrypha