At one point in The Return of the King Gandalf rides out of Minas Tirith to blind some Nazgul and immediately returns to Minas Tirith. It doesn't make sense to me why he would take Pippin along for that. He could have easily waited in Minas Tirith. Is there an explanation for this?
First, I don't think the reason for bringing Pippin along for a ride is for him to meet Faramir as has been previously stated. Here is why I disagree with that:
- that could've been done at any point once Faramir gets back to Minas Tirith quite trivially
- Faramir didn't seem to notice Pippin until they got back inside the gates, anyway
- Faramir wouldn't have had an opportunity to talk to Gandalf about Hobbits until they were back inside the city, of course, due to riding hard to escape the Nazgûl
- When Faramir does lay eyes on Pippin, it's the look on Faramir's face that prompts Gandalf to ask about other Hobbits Faramir might have seen. Before that moment, Gandalf has no idea Faramir even knows about Frodo & Sam, let alone has seen them or helped them.
Rather, this is probably an attempt to reinforce Gandalf's ruse about Pippin having the ring to keep Frodo and the real mission a secret.
Gandalf believes that Sauron, having seen Pippin through the Palantir at Edoras, believes Pippin is the Hobbit he's been looking for. If Pippin is not seen again anywhere, Sauron is likely to keep his search efforts spread across the land, increasing the danger that Frodo & Sam are caught by an enemy scout or patrol.
However, if Gandalf the White, of all people, rides out from Minas Tirith with a Hobbit on his horse to blind the Nazgûl, I'm pretty sure the Nazgûl will relay that information to Sauron. If Sauron thinks the Hobbit he's looking for is in Minas Tirith, Gandalf expects him to have the following thoughts:
- Why would Gandalf be keeping a mere Hobbit so close, if not to safeguard the ring?
- If the ring is in Minas Tirith, then Gondor must be trying to use the ring for purposes of power.
Both are enough reasons for someone with the mindset of Sauron to fix all his attention and forces on attacking Minas Tirith (which we see shortly after in the emptying of Cirith Ungol and the massive battle at Minis Tirith), allowing Frodo & Sam to continue their journey in secret.
For comparison, Pippin remains in the city in the corresponding section of the book.
...Pippin got up and peered out. At that moment he caught a flash of white and silver coming from the North, like a small star down on the dusky fields. It moved with the speed of an arrow and grew as it came, converging swiftly towards the Gate... But now the dark swooping shadows were aware of the newcomer. One wheeled towards him; but it seemed to Pippin that he raised his hand, and from it a shaft of white light stabbed upwards. The Nazgul gave a long wailing cry and swerved away...
Perhaps the movie changed this for the flow of Faramir meeting Pippin: rather than picking him out from the crowd, Pippin is right in front of him and impossible to miss.
'Faramir!' he cried aloud with the others. 'Faramir!' And Faramir, catching the strange voice among the clamour of the men of the City, turned and looked upon him and was amazed.
'Whence come you?' he said. 'A halfling, and in the livery of the Tower! Whence...?'
Out of universe:
Because it was shot for a different point in the story in the film and in editing was used later
Per Peter Jackson's commentary on "The Return of the King" Extended Edition, Gandalf and Pippin were originally shot meeting and fighting the Nazgul upon their initial arrival to Minas Tirith, before they had even gone into the city.
There is no in-universe reason. It's simply out of the originally intended sequence.
PJ does mention it in the director's commentary on Disc 1 at around 1 hour and 12mn