The gospels were written by folks who followed Jesus around. More than likely they took notes. Perhaps from time to time The Lord told them to write something down. We have several examples in Scripture where the Lord told His prophets to write it down.
Exd 17:14 And the LORD said unto Moses, Write this [for] a memorial in a book....
Exd 34:27 And the LORD said unto Moses, Write thou these words....
Isa 30:8 Now go, write it before them in a table, and note it in a book, that it may be for the time to come for ever and ever:
Jer 30:2 Thus speaketh the LORD God of Israel, saying, Write thee all the words that I have spoken unto thee in a book.
Jer 36:2 Take thee a roll of a book, and write therein all the words that I have spoken ...
Hab 2:2 And the LORD answered me, and said, Write the vision, and make [it] plain upon tables, that he may run that readeth it....
Rev 1:11 Saying, I am Alpha and Omega, the first and the last: and, What thou seest, write in a book,...
Rev 2:1 Unto the angel of the church of Ephesus write;...
Rev 2:8 And unto the angel of the church in Smyrna write...
Rev 2:12 And to the angel of the church in Pergamos write...
Rev 2:18 And unto the angel of the church in Thyatira write...
Rev 3:1 And unto the angel of the church in Sardis write...
Rev 3:7 And to the angel of the church in Philadelphia write...
Rev 3:14 And unto the angel of the church of the Laodiceans write...
Rev 21:5 And he that sat upon the throne said, Behold, I make all things new. And he said unto me, Write: for these words are true and faithful.