This event occurs at the end of Chapter 23, and comes as Holden is leaving his parents' appartment and Phoebe to spend the night at Mr. Antolini's place. Note how the text seems to suggest that Holden decided to give Phoebe his hunting hat in a spontanous act:
Then I took my hunting hat out of my coat pocket and gave it to her. She likes those kind of crazy hats. She didn't want to take it, but I made her. I'll bet she slept with it on. She really likes those kind of hats.
However, we need to be aware of the wider symbolic significance of Holden's red hunting hat. It is a bright, distinct and unique colour, and seems to operate in the novel as a symbol of Holden's desire to be unique and separate from everybody else. Thus, the way that, at this stage in the narrative, that he insists on giving it away to his sister, indicates a triumph in the internal conflict we see raging within him for the need Holden feels for companionship vs. his need for isolation. He has just spent time with the one character who he meets that he really connects with in every sense, and thus his willing sacrifice of his hunting hat is a symbol of his recognition that he does have ties and relations are important to him.
To begin, lets look at the name J.D Salinger chose as the main character in the book (Holden), Hold in. I think that Holden Bought the red hunting hat, because it was red. which remind him of Allie, who died of some diesease. And he gave the red hunting hat to Phoebe, because she had a red hair like Allie. And she was smart like Allie. And he finds out at the end that their is no possible way to stop kids from growing up. But the most important thing Holden found was himself.