In bereshis 21:17 it says
And G-d heard the lad's voice, and an angel of G-d called to Hagar from heaven, and said to her, "What is troubling you, Hagar? Fear not, for G-d has heard the lad's voice in the place where he is.
Which the gemarah, Rosh HaShanah 16b, says teaches us that
A person is judged only based on his deeds of that moment, as it is written, ‘G-d has heard the voice of the youth [Yishmael], as he is there.
Rashi, quoting the Midrash Rabba fills in
For the ministering angels were accusing and saying,“ O L-rd of the Universe, for one who is destined to kill Your children with thirst, You are bringing up a well?!” And He answered them, “What is he now, righteous or wicked?” They replied, “Righteous.” He said to them, “According to his present deeds I judge him” (Gen. Rabbah 53:14)
But was Yishmael righteous? 8 Pesukim earlier we find
וַתֵּרֶא שָׂרָה אֶת בֶּן הָגָר הַמִּצְרִית אֲשֶׁר יָלְדָה לְאַבְרָהָם מְצַחֵק Which Rashi, from the midrash, explains as making merry: Heb. מְצַחֵק. An expression of idolatry, as it is said (Exod. 32:6):“and they rose up to make merry” (לְצַחֵק) . Another explanation: An expression of illicit sexual relations, as it is said (below 39:17):“to mock (לְצַחֶק) me.” Another explanation: An expression of murder, as it is said (II Sam. 2:14):“Let the boys get up now and sport (וַיִשַׂחֲקוּ) before us, etc.” - [from Gen. Rabbah 53:11]
So Yishmael engaged in at least one and possible all three of the cardinal sins, which are also capital offenses for a Ben Noach.
Why then is he dubbed "righteous" and not put to death?
And if you wish to answer that yishmael was saved out Hashem mercy such as repentance or Abraham's merit, then why does the Torah only use Elohim (which signifies strict justice) and not Hashem (which is mercy)?