Jesus spoke with his Apostles during his ministry and appeared to them several times and spoke with them after his resurrection. (Acts 1:1-3) During these times Jesus could’ve told them any additional facts He wanted them to know. In addition, after Pentecost the disciples have been baptized in the Holy Spirit. From that time on they’re experiencing heavenly visions (Acts 9:10; 10:9-20; 16:9), interacting with angels (Acts 5:19-20; 8:26; 12:1-11) and hearing the Holy Spirit speak to them (Acts 13:2; 16:6). So God could’ve shown the Gospel writers in a vision what took place, had an angel instruct them, or for that matter had the Holy Spirit dictate the text to them directly. Note that Paul says plainly that he received the gospel, not by being taught by others, but by revelation directly from Jesus (Gal 1:11-12).
This issue of how the Gospel writers could have known certain things is really only a problem for those who try to read the Bible in a way that eliminates the supernatural element from the Scriptures.