the worshipper does not have to intend exiting the prayer when saying the tasleem; if he says the tasleem without intending that, it is acceptable. This is the view of the majority of fuqaha’ among the Hanafis, Shaafa‘is and Hanbalis.
Ibn Qudaamah (may Allah have mercy on him) said: He should intend when saying the tasleem to exit the prayer. If he does not have that intention, then Ibn Haamid said that his prayer is rendered invalid, and this is the apparent meaning of the statement of ash-Shaafa‘i, because it is uttered at one of the two ends of the prayer, so having the intention is essential, as is also the case with the takbeer (at the beginning of the prayer).
What was narrated from Ahmad (may Allah have mercy on him) is that it does not render his prayer invalid, and this is the correct opinion, because the intention to pray covers all of the prayer, and the salaam is part of it. And because if it were obligatory to form the attention when saying the salaam, there should have been some text to specify that, as with the opening takbeer, and because it is an act of worship. So it is not required to form the intention to exit the prayer, as is also the case with other acts of worship.) Drawing an analogy between the end of the prayer and the beginning is not correct; the intention is regarded as essential at the beginning so that it covers all other parts of the prayer, unlike the ending. Hence there is a differentiation between the beginning and end in all acts of worship.
Some of our companions said: He should intend, by saying both tasleems, to exit the prayer. If he intends thereby to return the salaam of the two angels and of those who are behind him if he is the imam, and of the imam and the other members of the congregation if he is praying behind an imam, there is nothing wrong with that. This was stated by Ahmad who said: He should say the salaam in the prayer and intend by saying it to respond to the imam, because of the report narrated by Muslim from Jaabir ibn Samurah who said: When we prayed with the Prophet (sa), we used to say: As-salaamu ‘alaykum, as-salaamu ‘alaykum. The Messenger of Allah (blessings and peace of Allah be upon him) looked at us and said: “Why do you wave your hands like the tails of restive horses? When one of you says the salaam, let him turn to his companion and not wave his hand.” According to another report: “It is sufficient for one of you to put his hand on his thigh, then say the salaam to his brothers on his right and on his left. Abu Dawood narrated: The Prophet (blessings and peace of Allah be upon him) instructed us to respond to the imam and to say salaam to one another.
This indicates that it is Sunnah to intend by saying the salaam to greet one’s fellow worshippers. This is the view of ash-Shaafa‘i and Abu Haneefah. Abu Hafs ibn al-Muslim – one of our companions – said: He should intend by the first salaam to exit the prayer and he should intend by the second to greet the recording angels and the members of the congregation, if he is the imam, and to respond to the imam and the recording angels if he is praying behind an imam.
End quote from al-Mughni, 1/326
An-Nawawi (may Allah have mercy on him) said: Is it necessary to intend by saying the salaam to exit the prayer? There are two well known opinions concerning that, the more correct of which according to the Khorasaanis is that it is not obligatory, because the intention of praying includes the salaam. This is the view of Abu Hafs ibn al-Wakeel and Abu ‘Abdillah al-Khatan, as was stated in al-Musannaf. Imam al-Haramayn said: It is the view of the majority.
(The second opinion) is that it is obligatory. This is the more correct view according to the majority of the Iraqis. In al-Musannaf (may Allah have mercy on him) it says: This is the apparent meaning of the statement of al-Buwayti. It is also the opinion of Ibn Surayj and Ibn al-Qaas. The author of al-Haawi said: It is the apparent meaning of ash-Shafaa‘is view, and the opinion of the majority of his companions, by analogy with the beginning of the prayer.
The correct view is the first one. Ar-Raafa‘i said: This is the favoured view of the majority of later scholars. They interpreted the statement of ash-Shaafa‘i as meaning that it is mustahabb.
End quote from al-Majmoo‘, 3/457
See: al-Badaa’i‘ wa’s-Sanaa‘i, 2/214
The Maalikis have two opinions
It says in at-Taaj wa’l-Ikleel (2/219): There is a difference of opinion about stipulating that the intention to exit (the prayer) be formed. Ibn Rushd said: Just as one cannot start to pray without the takbeer, intending thereby to start the prayer, by the same token he cannot exit the prayer except by saying the tasleem, intending thereby to exit the prayer. If he says the tasleem at the end of his prayer without the intention, that is acceptable because of his previous intention, because he does not have to renew the intention for every part of the prayer. Ibn al-Maajishon said: It is essential to renew the intention to exit (the prayer). Ibn al-‘Arabi said: The well-known opinion of our madhhab differs from that. End quote.
And Allah knows best.