The only theory that I've ever made regarding the ending apart from headcanoning what comes after helps explain how that last scene with Anderson, Shepard, and TIM was able to happen without it just being some kind of dream/indoctrination:
1. You and Anderson are running toward the beam, then Harbinger comes along to stop anyone from going. Since Anderson was a distance behind you [not sure how far exactly], when Harbinger fired the shot that severely injured you, he didn't get hurt as badly since you were closer. And because of that, he was able to get up and finish the trip before you regained consciousness, and thus he got up to the citadel before you.
2. Anderson was beamed up into a hallway that looked identical to the one Shepard went into, but [here's the meat of my theory starting now] the part of the Citadel where the beam takes you is actually shaped sorta like this:

And the beam alternates which hallway a rider winds up at so that each hallway has the same number of victims in them. This means Anderson wound up in hallway B, Shepard wound up in hallway C, if a third person would have made it then they would have wound up in hallway D, so on and so forth. Once they both made it up to their hallways, they both started making their way towards the hub, and because Anderson was in slightly better shape after the Harbinger attack, he was able to more quickly reach the hub.
3. Now the chasm with the sliding hexagons. This chasm is actually the transporting mechanism between the hub and the hallways, and it acts as sorta like a horizontal elevator, but instead of just the bridge turning, it is actually rotating the entire hub so that a Keeper or anyone who reaches the end of the hallway can move on to the hub. It turns sorta like a wrench, with the sliding hexagons acting as the teeth of a gear rotating that entire hub from hallway to hallway.
4. Once Shepard finally reaches the hub, Anderson was already there because he reached the end of his hallway first and was able to get into the hub in time for the hub to rotate to Shepard's hallway. Then they have their chat until TIM, who was actually in hallway A [likely compelled to go there by his reaper overlords] this whole time walked to the end of the hallway he was waiting in and the hub rotated to his hallway. Since the whole hub would have rotated, Shepard and Anderson who were already in the hub wouldn't have noticed the rotation, thus allowing for TIM to surprise them [and in turn the player]. Then the rest of the ending of the game happens.