Rulebook 3.1.3 wrote:
"Once the units being transported have mounted up, the war engine can move off with them inside as part of one of its own actions in a subsequent turn. It can dismount the transported units at the end of a move in the same way as a normal transport vehicle (ie, the units are placed within 5cms of the transport at the end of a move).
Formations that dismount in this way may not take an action in the turn they dismount, but are allowed to either shoot or fight in an assault if the war engine that was transporting it is able to shoot or assault. In both cases, the war engine and the transported units are treated as a single formation until the shooting attack or assault has been resolved. The war engine and the formation that disembarked are treated as being separate formations once the war engine has completely resolved its action."
The war engine takes its action, and the transported formations count as being part of its formation, may shoot when the transporting formation can (assuming they are in a position to), and only count as being a separate formation at the end.
Remembering that the order of precedence is: army special rules > war engine rules > basic rules (i.e. the reverse order in which they are written), the Hit and Run rule is a modification that allows the shooting attack to happen between the two moves of a double. The war engine rules couldn't anticipate this, so the rules make no distinction between
until the shooting attack has been resolved and
once the war engine has completely resolved its action. So there is some ambiguity in whether the formations should split up after they shoot or at the end of the action. However, remember that assault and shooting actions arent the only ones that might lead to dismounting troops, so IMO it is quite clear that the last sentence is intended to be the clear and unequivocal moment when dismounted formations are considered to be separate, i.e. at the very end of the action.
Note that at this point, they are considered part of the same formation - so it is not the war engine rules that allow them to re-embark, it is the regular transport rules:
Rulebook 3.1.3 wrote:
"Note that a war engine may carry other units from its own formation using the normal rules (see 1.7.5)."
In that context, a) the effects of embarking leading to losing the WE's action is a red herring - that applies when it is the
transported formation that is taking an action to board the WE, and b) the only special thing about the 'dismounting from a war engine' rules is the splitting up - everything else is exactly as it is in the regular rules. If they're dismounted at the end of the war engine's action, just split them up.