TT #100 · Parashas Shoftim · Second Aliyah · Passuk 17:16
Only he must not multiply horses for himself, or cause the people to return to Egypt in order to multiply horses, since the Eternal has said to you, ‘You shall not return that way again.’
Torah Temimah points to Sanhedrin 21b.
TT lemma: לְמַעַן הַרְבּוֹת סוּס.
English: ‘In order to multiply horses’ – this implies that if he is not multiplying horses, it is permitted.
Derash on the purpose clause (Bavli) — the prohibition is tied to the specific goal of multiplying horses.
The ban focuses on returning to Egypt in order to increase the royal horse supply. Other limited contacts are treated differently by the sugya.