For each planet with a trade port, the game calculates the shortest route to each other planet with a trade port, passing only through other systems which have a trade port (or systems which cannot support a trade port). The longest route between any two planets (passing only through other TP systems) is then saved as the trade route 
The reason for this, I think, is to encourage people to place trade ports on (almost) every planet they colonise, rather than just dumping loads of trade ports on odd planets.