The Old Man bought the Red Ryder BB Gun because Ralphie got into a fight and he wanted to show he was proud of him
https://www.reddit.com/r/FanTheories/comments/a8qgrd/a_christmas_story_the_old_man_bought_the_red/
When Ralphie says the F word his Father immediately tells the mother when they get in the car, establishing that when it comes to the kids they don't hold back secrets about what they're doing no matter how bad and how shocking.share
Later when Ralphie beats up Scut Farkus his mother breaks up the fight and brings him home where he's terrified his father will find out. No one seemingly says anything but this is perhaps because Ralphies mother has a little more tact and timing than to blurt out that Ralphie got into a fight.
It's likely that when she told the old man Ralphie had been in a fight and that the whole situation was handled he wasn't upset but rather proud of his son for standing up for himself. So it's likely he asked if they got Ralphie anything a little more special this Christmas and this is when the mother mentioned what Ralphie wanted.
Fast forward to Christmas Eve when Ralphie goes to see Santa, now it's very likely the entire day he was talking up how he needed to see Santa, it was important to him and the old man stood back letting Ralphie grow concerned and then instead of waiting in line with his son to see Santa, went off with his mother to buy the Red Ryder BB Gun and put it in the car.
When Ralphie gets tossed by Santa the old man asks a few telling questions and when he asks Ralphie if he's been bad or good he says that Santa always knows.
See he's proud that his son stood up for himself and handled himself like a man, so he got him the gun for Christmas.