Is it just the closest system with less than 7 factions? or can you get pulled into a low faction (4) that's twice the distance (16ly)
or is it more complicated than that (as most things seem to be in the BGS)
It's *mostly* "closest with less than 7 factions" and that will predict your destination almost all the time, but yes, there are more complications.
Priorities seem to be as follows:
1) Closest* system with <7 factions that you have not retreated from since October 2017
2) Closest* system with <7 factions that you have retreated from since October 2017
3) Closest* system with 7 factions that you have not retreated from since October 2017, provided that there is an eligible target faction not native to that system, and you are not pending a conflict. (Invasion)
4) Closest* system with 7 factions that you have retreated from since October 2017, provided that there is an eligible target faction not native to that system, and you are not pending a conflict. (Invasion)
5) Do some Investment
* There are then at least three complications on "closest".
a) Systems very close in relative distance - within 1LY - may sometimes be selected in the opposite order you'd expect
b) Retreats and expansions are processed serially, so a faction moving "before" you on the same tick may change what the closest system with <7 factions is
c) A small number of systems are completely blocked to all expansions - superpower capitals and other highly important systems. A larger number - the Permit systems - have an additional restriction to make them harder to expand into but the nature of this restriction has not been researched - it might be "you can't" or it might be "you have to expand to everywhere else in range first", or something else.