From Bart Ehrman book "Forged":
The anonymity of the Gospel writers was respected for decades. When the Gospels of the New Testament are alluded to and quoted by authors of the early second century, they are never entitled, never named. Even Justin Martyr, writing around 150-60 CE, quotes verses from the Gospels, but does not indicate what the Gospels were named. For Justin, these books are simply known, collectively, as the "Memoirs of the Apostles." It was about a century after the Gospels had been originally put in circulation that they were definitively named Matthew, Mark, Luke, and John. This comes, for the first time, in the writings of the church father and heresiologist Irenaeus, around 180-85 CE.
Irenaeus wrote a five-volume work, typically known today as Against Heresies, directed against the false teachings rampant among Christians in his day. At one point in these writings he insists that "heretics" (i.e., false teachers) have gone astray either because they use Gospels that are not really Gospels or because they use only one or another of the four that are legitimately Gospels. Some heretical groups used only Matthew, some only Mark, and so on. For Irenaeus, just as the gospel of Christ has been spread by the four winds of heaven over the four corners of the earth, so there must be four and only four Gospels, and they are Matthew, Mark, Luke, and John. 4
Modern readers may not find this kind of logic very compelling, but it is not difficult to see why orthodox writers like Irenaeus wanted to stress the point. Lots of Gospels were in circulation. Christians who wanted to appeal to the authority of the Gospels had to know which ones were legitimate. For Irenaeus and his fellow orthodox Christians, legitimate Gospels could only be those that had apostolic authority behind them. The authority of a Gospel resided in the person of its author. The author there- fore had to be authoritative, either an apostle himself or a close companion of an apostle who could relate the stories of the Gospel under his authority. In the year 155, when Justin was writing, it may still have been perfectly acceptable to quote the Gospels without attributing them to particular authors. But soon there were so many other Gospels in circulation that the books being widely cited by orthodox Christians needed to be given apostolic credentials. So they began to be known as Matthew, Mark, Luke, and John.