Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:4:86

And when you are greeted with a greeting, greet ˹in return˺ with one better than it or ˹at least˺ return it ˹in a like manner˺. Indeed, Allah is ever, over all things, an Accountant.  

And when you are greeted with a greeting, as when it is said to you, ‘Peace be upon you’, greet, the one that greeted you, with better than it, by responding to him with, ‘Peace be upon you, and God’s mercy and blessings’, or return it, by saying back to him what he said; in other words, it is a duty to greet in one of these two ways, the former being the preferred one. Surely God keeps count of, He holds ˹you˺ accountable for, all things, and requites accordingly, including things such as returning a greeting. The Sunna specifies that one should not return the greeting of an disbeliever, an innovator, a wicked person, and of the one that greets a person who is in the act of relieving himself, or one in the bath, or one eating — indeed it is actually disapproved with the exception of the last. To the disbeliever ˹who says ‘peace be upon you’˺ one should simply say, ‘And upon you’.
القرآن:٤:٨٦

وَإِذَا حُيِّيتُمْ بِتَحِيَّةٍ فَحَيُّوا بِأَحْسَنَ مِنْهَا أَوْ رُدُّوهَا ۗ إِنَّ اللَّهَ كَانَ عَلَىٰ كُلِّ شَيْءٍ حَسِيبًا  

{وإذا حُيِّيتم بتحية} كأن قيل لكم سلام عليكم {فحيُّوا} المحيِّي {بأحسن منها} بأن تقولوا له عليك السلام ورحمة الله وبركاته {أوردُّوها} بأن تقولوا له كما قال أي الواجب أحدهما والأول أفضل {إن الله كان على كل شيء حسيبا} محاسبا فيجازي عليه ومنه ردُّ السلام وخصّت السنة الكافر والمبتدع والفاسق والمسلِّم على قاضي الحاجة ومن في الحمام والآكل فلا يجب الرد عليهم بل يكره في غير الأخير ويقال للكافر وعليك.