This is really up to you and how you want to handle your logistics. Strictly speaking, they should probably be awarded the XP immediately after successfully handling the encounter. However, look at your players, your play style, and your session flow to make the best choice. Over the years I've seen XP rewards handled the following ways.
Immediately After Encounter
Like I said, this is likely the most "realistic" since XP is the mechanical abstraction of what the characters learned during the encounter. This provides some immediate feedback to the players, and can really help motivate them along the way. For instance, a player will earn experience for surviving a trap, but maybe not as much than if they disarmed it. By awarding XP immediately there is a pretty fantastic feedback that can help demonstrate this, and may help guide them towards more heroic actions. The biggest downside is that this can slow down play. After every encounter the DM will have to do some math and figure out who earned what XP. Additionally, if the players earned enough XP to advance, then they'll want to stop and level up their characters. This can really destroy game pacing unless the players can churn out new levels in less time than your typically bathroom break.
End of Each Session
This is what I saw the most of, when I still played in groups that tracked experience. The end of the game session is a natural break point that allows the DM to look over their notes for the night and tally up the XP rewards. If the players level this allows them to naturally level between sessions, that night before they leave, or the beginning of the next session. In any case, it pushes leveling off to non-play time and minimizes disruption of the game flow. In exceptionally long play sessions, I'm thinking of my 12+ hour sessions from college, you can also do this during natural break points in the game. Say, before taking a meal break or a mini-climax in the story. On the down side, depending on what your players are facing, this means they may end up being one level behind what you expected when they hit a certain encounter. The biggest advantages is that it bypasses the story disruption that can occur when leveling happens.
Pacing Based Rewards
This is what I've been seeing more of lately, and is the way my group has been playing for the past few years. We stopped tracking experience entirely. Most pre-written adventures will give you some rough guidance about what level characters should be as they reach certain sections. For instance, in a level 4-7 adventure there is likely a sidebar at the beginning that says, "Players are expected to be level 5 before entering this area, 6 before entering this area, and 7 before this spot." This provides you the natural story based breakpoints to introduce leveling. To accomplish this, we work on our pacing such that we end a session just before one of those points happens, and announce that it's leveling time. The biggest advantages we've found are these:
- Since the players don't have to completely explore and clear the dungeon in order to hit their experience budget, it allows them to slow down and really dive deep into something if it catches their eye.
- It makes it a lot easier for us to take a machete to the dungeon crawls and carve out those areas that aren't relevant to the story. Since designers are working against an XP budget to make the levels work, these things are chock full of unimportant encounters and unnecessary rooms. Not tracking experience means these encounters don't have to happen for the math to work out.
- Since everyone levels at the same time, we can bulk manage the maintenance of leveling and get it all out of the way at once. Plus you don't have to worry about that one guy who sporadically misses to be 6 levels behind everyone towards the end of the campaign.
My current group, because of work and family, really only gets about 3 hours per week of play time. This also means that leveling 5-6 players can take an entire game session. Which is why it works so well for us to do it this way. When I was younger, and we had multiple sessions per week at 5-12 hours each, then we found the End of Session/Story Break method worked the best. The only time I played with awarding XP immediately after each encounter, and found that it worked well, was when leveling only occurred outside of play. For all practical purposes, this was the exact same as End of Session.