Good grief.
How did the Gospels come to be? That is the question. One guess is the same way that the Prophecies came to be. The idea that the teachings and the deeds of Jesus were recorded only long afterwards is one that serves the agenda of liberal scholars who wished to discredit the authority of the Bible as an historical record.