John 3 - Jesus teaches Nicodemus
John 4 - Woman @ the Well
John 17 - Jesus prays for his disciples + Believers
John 18 - Jesus and Pilate
Jesus' temptation(s) in the wilderness by Satan (in Matt. 4 & Luke 4)
There are two common answers to this question:
A. Inspiration
All scripture is given by inspiration of God (2 Tim. 3:16)
On this view the authors learned of these details by revelation from God, much like Peter learned of Jesus' identity in this way, as recorded in Matthew 16: 15-17
B. These people talked to each other
1. Nicodemus - we learn in John 19:39 that Nicodemus retained belief in Jesus; there is no reason to conclude that he forever kept the events of John 3 to himself.
2. The woman at the well - we learn in John 4:28,29,39 that the woman got right to work telling many other people about the experience.
3. The intercessory prayer - At least 3 of Jesus' disciples were within earshot the entire evening prior to the arrest. That they fell asleep at some point does not indicate they slept the entire time (compare John 18:1 with Matt. 26:36-40, suggesting Peter, James, and John did not fall asleep until after the aforementioned prayer). John may well have heard this prayer firsthand.
4. The trial - Roman trials were intentionally public. It is apparent from John chapters 18-19 that a dearly beloved disciple of Jesus (often taken to be John) stayed around and witnesses the events of the trial and crucifixion.
5. The temptations - the Gospels are silent on when/how this information was disseminated...but this does not mean Jesus didn't tell anyone the story. That the temptations show up in Matthew & Luke with slight variation suggests that Jesus related this story more than once, in different levels of detail, so multiple people would have heard the story.
Summary of probable circumstances for option B
For #'s 1 & 2, John could easily have heard of these events from those who were there
For #'s 3 & 4, I suggest that John was present
For #5, Matthew heard the story from Jesus and Luke heard it from "those who were eyewitnesses from the beginning"
Conclusion
I have no difficulty believing some combination of both options took place. Jesus also promised in John 14:26 that the Holy Ghost would bring His teachings to their memory, suggesting a bit of both A & B.
My own work on the history of the Gospels leads me decisively to the conclusion that notes were taken during Jesus' ministry, and that "there were many other things Jesus did", a small portion of which were extracted from contemporary notes, later reflections, and subsequent interviews, to form the Gospel record.
I’m a bit late to this party, but don’t see this response yet: isn’t it possible that during the 40 days he was with the disciples after the Resurrection, Jesus went into significant detail about this and other events they had been oblivious to? After all, there are times in the Gospels where it relates the inner thoughts of Jesus, which they had no way of knowing about unless Jesus Himself had told them about it. Perhaps those insights, too, happened during those 40 days after the Resurrection?