Not really sure but iirc each city can trade with each other city if it wants to (only one-sided restrictions for the number of trade routes) so the game uses the cities that generate the most income to trade with.
Which factors influence that, I have no idea though.