I think it’s super easy to make the assumption that Spock is the XO given he would hold that position for most of the following 30+ years. Not to mention the fact he was already on the ship and likely came highly recommended by Pike.
but it’s just as easy to think that Kirk, on his first major command would bring over his best friend to help run the ship. Someone he trusts without question.
The episode is definitely vague about which one is the first officer. On the one hand, Spock is wearing a yellow command shirt, which implies that he's somewhere in the command structure. At the very least, he seems to assume the duties of first officer after Mitchell is incapacitated. So he's at least third in command at the time of WNMHGB. And it's very likely he would've earned the position by the time Kirk took over. But he doesn't seem to do much outside of his science officer duties early on.
On the other hand, Kirk and Mitchell are very close. He casually addresses Kirk as "Jim" in front of Spock in the turbolift on the way to the bridge at the beginning of the episode, which doesn't seem likely if Mitchell wasn't second in command. It's Mitchell who opens the intercraft for Kirk to address the entire ship and it's Mitchell who tells Kirk that all the department heads are on the bridge. Those certainly seem like first officer duties to me. And Dr. Dehner says (repeating information from Gary) that Kirk asked for Mitchell on his first command. It seems that Kirk most likely would've requested Mitchell as first officer, and we know that Number One also doubled as first and helm officer.
But the episode never definitively says what Mitchell's position is one way or the other, as the script emphasizes Gary's long friendship with Kirk over his exact title. And we only have about five minutes of footage of the normal operations of the
Enterprise to go on before Mitchell is altered by the Great Barrier. So it's interesting to contemplate.
Personally, I think that Mitchell was the first officer for Kirk's first few months on the ship. Kirk would more likely pick someone he was close with, and I like the idea of Spock inheriting Mitchell's position after his death, eventually becoming Kirk's new best friend as well.
(BTW, my personal headcanon is that Mitchell was actually assigned to the
Enterprise before Kirk took command. That's how he knew Spock "for years" by the time of WNMHGB. The first command that Kirk requested Mitchell for was the cruiser he commanded before the
Enterprise, but Mitchell was unavailable for that position. But as luck would have it, Kirk took command of the
Enterprise himself a couple of years later. So at the time of WNMHGB, Mitchell actually knew Mr. Spock at bit better than Kirk did at that point.)