Does the commander in the modern XCOM series have a canonical gender?
While playing XCOM 2 it seemed to me as if the dialog authors went to great lengths to avoid referring to the player-character with any pronouns. They always refer to the character as "The Commander", even in lines where using a pronoun would have seemed much more natural. I suspect that they consciously tried to avoid gendering the player. But maybe that's just my imagination.
While doing my own research I found several interviews with people from Firaxis where they mentioned that diversity was very important to them during the development of the new XCOM games, but they focused mostly on the squad members, not on the commander.
Is there any situation where the writers slipped up and referred to the Commander as "he" or "she" or otherwise implied their gender? Examples from the first part would count, as the commander from XCOM: Enemy Unknown is canonically the same person.
No, the idea of the Commander is that you, the player, are the Commander. The gender of the Commander is your own (or whatever you want it to be). As you've noticed, the game carefully dances around assigning a gender by only strictly referring to you as "the Commander" and refraining from using gender-specific pronouns.
This is backed up by the wiki page on the Commander:
You play as The Commander, who is the main brains behind all of XCOM as he/she manages the XCOM project. He/she decides everything that happens from; what research project to start next, to commanding the troops on where to move on the battlefield. The commander's true form is completely unknown implying that you (the player) are the commander.
Further down the page, it also has gender listed as being unknown:
Gender: Unknown (either male or female)
This is actually a trope featured on the game's TVTropes page for the characters in multiple places:
Ambiguous Gender: Their gender is never referred to in game, allowing any player to identify with them.
Featureless Protagonist: The Commander gets an in-game model... as a bulky self-contained suit that obscures any identifiable features, including gender. All the better for the "self insert" Non-Entity General role taken up for the rest of the game. The Commander's Avatar looks like any other.
In X-Com 2: War of the Chosen, the gender does seem to be specifically ambiguous. There's a Resistance Radio broadcast where it's suggested that no one knows the commander's gender. The speaker says specifically "I don't know the commander's gender." Granted, it could be that other people know the gender, but it seems like it's a secret/ambiguous.