It was before Mathan Torah
A heavenly voice told him to, and he listened and they cleaved to HBKH, and reciprocally the Shekhinah bound to them actually in their very act and never left them and Moshe who went out from him.
Zohar II 11b top
"And a [great] man went" – this is Amram. "And took a daughter of
Levi (bat-Levi)" – this is Yokheved. A bat-kol (heavenly voice) came
down and told him to be matched with her, for behold the time of
Yisrael's salvation has come, via the son that will be born by her.
And HKBH helped him, for we've learned a tanya: The Shekhinah rested
on his bed, and their will, in one cleaving was in the Shekhinah, and
for this reason the Shekhinah never departed from that son they bore,
to fulfill the scripture (Lev. 11:45), "Holy yourselves and you shall
be holy." A mortal who sanctifies himself below, HKBH sanctifies him
above. Just as their will was in the bond of the Shekhinah, so too
that Shekhinah bonded in that actual act that they did.
Said R' Yitzchak, Fortunate are those tzadikim that their will is in
the bond of HKBH always. Just as they always bind to him, so too He
binds to them, and never leaves them. Woe to the wicked, that their
will and their bond is in distancing from Him. And not enough for
them that they distance from Him, rather they bind to the Sitra Achra.
Come and see: Amram who bonded with HKBH, Moshe came out from him, for
HKBH never left him, and the Shekhinah clung to him perpetually.
Fortunate is their lot!
וילך איש, דא עמרם, ויקח את בת לוי, דא יוכבד, ובת קול נחתת ואמרת ליה
לאזדווגא בה, דהא קריב זמנא דפורקנא דישראל על ידא דברא דאתיליד מנייהו,
וקודשא בריך הוא סייע ביה, דתנינן שכינתא שריא על ערסייהו, ורעותא דלהון
בדבקותא חדא הוה בה בשכינתא, ועל דא לא אתעדי שכינתא מההוא ברא דאולידו,
לקיימא דכתיב (ויקרא יא מד) והתקדשתם והייתם קדושים, בר נש דמקדש גרמיה
מלרע, קודשא בריך הוא מקדש ליה לעילא, כמה דרעותא דלהון הוה בדבקותא
דשכינתא, הכי אתדבקא שכינתא בההוא עובדא ממש דעבדו. אמר רבי יצחק, זכאין
אינון צדיקיא דרעותא דלהון בדבקותא דקודשא בריך הוא תדיר, וכמה דאינון
מתדבקין ביה תדיר, הכי נמי איהו אתדבק בהו, ולא שביק לון לעלמין, ווי
לרשיעייא דרעותא דלהון ודבקותא דלהון מתרחקא מניה, ולא די להו דמתרחקן
מניה, אלא דמתדבקן בסטרא אחרא, תא חזי עמרם דאתדבק ביה בקודשא בריך הוא,
נפיק מניה משה, דקודשא בריך הוא לא אעדי מניה לעלמין, ושכינתא אתדבקת
בהדיה תדיד, זכאה חולקיה: