TT #102 · Parashas Shoftim · Second Aliyah · Passuk 17:17
And he must not multiply wives for himself, so that his heart not turn away; and he must not greatly multiply silver and gold for himself.
Torah Temimah points to Sanhedrin 21b.
TT lemma: וְלֹא יָסוּר לְבָבוֹ.
English: ‘So that his heart not turn away’ – this implies that if his heart does not turn away, it is permitted.
Derash on the purpose clause (Bavli) — the ban is directed against the spiritual danger, not against marriage itself.
The Torah’s concern is that multiple wives not lead the king’s heart astray. Where that danger is absent, the law is read more leniently by the sugya.