The command “do not set forth comparisons for Allah” forbids comparisons invented by people themselves.
A person must not devise a likeness for Allah by personal conjecture or analogy. When Allah Himself gives an illustration to explain a meaning, that illustration is of a different kind.
Thus, a humanly invented comparison is not the same as an illustration stated by Allah. The passage in Sūrat al-Nūr is understood as a divinely given illustration.