When are the statistics (IVs/Ability/Gender etc.) for a hatched Pokémon randomised?

Eggs are generated when you pick them up. As soon as you choose to receive an Egg, the game calls the Egg RNG (Random Number Generator) to determine the Pokemon's characteristics.

The big difference to previous generations is that this Egg RNG is completely independent and never reseeded. It's exclusively used for eggs and once the starting seed is determined (presumably when the game is first started), it carries over forever and is saved with the game. This leads to soft resets not having any effect and allows for exact predictions assuming the current seed can be determined.

One notable detail is that the PID (which determines shininess and not really anything else nowadays) is generated by yet another RNG, potentially the game's main RNG, and is thus unpredictable for practical purposes. However, when shiny charm or the Masuda method are used, this initial PID is discarded and additional PIDs are generated by the Egg RNG, making shininess predictable again if either or both of these methods is used.

The Japanese community have put a great deal of effort into this and discovered nearly the entire mechanics behind this by the time the English-speaking community independently discovered there was something fishy. There is actually an English guide made by one of the Japanese researchers that details how to determine the current seed and use a tool created for this specific purpose to predict eggs and even search for specific characteristics.

My sources are various, most of them are google-translated Japanese sites and personal experiences. The guide linked above sums up the relevant information for anyone who's not too interested in the actual programming stuff going on.