And the evidence for the distinction between speaking in prayer out of forgetfulness and speaking in prayer intentionally is that our opponents from among the Iraqis agree with us on the distinction between giving salam before completing the prayer intentionally and giving salam out of forgetfulness. So they obligate the one who gives salam intentionally to repeat the prayer, and they permit the one who gives salam forgetfully in the prayer to complete the prayer and to build upon what he has already prayed before the salam.
It is narrated from Sayyiduna Muawiyah bin Hudaij (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) led the prayer one day, and before completing the prayer, he said the salam, although one rak'ah of the prayer was still remaining.
Hadith Referenceصحيح ابن خزيمه / جماع أبواب السهو فى الصلاة / 1052