Sueño (Spanish for “dream”) and insomnia come from the same root: the Latin somnus, meaning, “sleep.”
The evolution is easy to spot if we remember that the -mn- sound in Latin usually transformed into the ñ in Spanish. See damn and daño, for example. Or autumn and otoño as well.
Thus, the s-mn of insomnia maps to the s-ñ of, sueño.