I have been asked this question a few times. It is an obvious question to think about. Here is the problem. We do not know the answer. All we can do is make a logical guess. In the case of Jesus before Pilate, we can assume that there were multiple witnesses, some of whom became disciples of Jesus. Also, Jesus spent a good amount of time with the apostles after his resurrection. He may have told them many of the details of the terrible events of his execution. Which was it? How did John and others get this information? It could be from other witnesses or from Jesus directly. As for Herod, more than one member of his household were converted. This is recorded in the New Testament. Joanna, the wife of Chuza, is mentioned in Luke 8:2 and Luke 24:10. Chuza was the manager of Herod’s household. It is entirely possible that Luke actually interviewed Joanna. He clearly interviewed some witnesses, as can be seen from his account. As for Pilate and Herod becoming friends, this would have been more common knowledge than the other two.
Like I said, we do not generally have recorded who told what to whom, but in these cases, there is a perfectly reasonable path for the knowledge of what happened to get into the hands of those who wrote the gospels.