All praise is due to Allah, and peace and blessings be upon the Messenger of Allah. To proceed:
The principle established by the Qur'an and the Sunnah, and unanimously affirmed by Ahl al-Sunnah wa al-Jama'ah, is that major sins do not nullify all of a Muslim's good deeds. Rather, what completely nullifies one's deeds is disbelief (kufr) and associating partners with Allah (shirk) if a person dies upon them.
As for the one who commits a major sin, such as adultery (zina), they do not leave Islam merely because of that sin. Their good deeds remain, and they are rewarded for the righteous actions they performed sincerely for Allah and in accordance with the Sunnah, while still deserving punishment for their major sin if they do not repent.
The scholars have explained that some sins may reduce the reward of certain acts of worship or even eliminate the reward of particular deeds, but they do not invalidate all good deeds as disbelief does.
As for the Prophet's ﷺ hadith describing people who will come on the Day of Judgment with good deeds as great as the mountains of Tihamah, only for Allah to scatter them like dust, it is a severe warning to those who secretly violate Allah's prohibitions. It indicates that some sins may erase the reward of great deeds, but it does not mean that every person who commits a major sin loses all of their good deeds.
Likewise, the hadith concerning the non-acceptance of the supplication of a prostitute who persists in adultery or an unjust tax collector does not mean that all of their deeds are nullified. Rather, it indicates that persisting in sin is among the reasons why supplications may not be answered until the servant sincerely repents to Allah.
Summary
Major sins, including adultery, do not nullify all righteous deeds. What completely nullifies one's deeds is apostasy and disbelief. A Muslim continues to receive the reward for sincere acts of worship while remaining under Allah's will if they die persisting in a major sin. Therefore, one should hasten to repent and never rely on good deeds while continuing to persist in disobedience.
And Allah knows best.