Sayyiduna Abu Hurairah (may Allah be pleased with him) narrates that the Noble Prophet (peace and blessings be upon him) said: "Indeed, Satan comes to one of you while he is performing his prayer, and he confuses his prayer for him, until he does not know how many rak‘ahs he has prayed. So whoever faces such a situation should perform two prostrations while sitting." The meaning of the narration from Yahya bin Abi Kathir and Muhammad bin ‘Amr is also similar, that Sayyiduna Abu Hurairah (may Allah be pleased with him) narrates from the Noble Prophet (peace and blessings be upon him) that he said: "Until the state of the one praying becomes such that he does not know how many rak‘ahs he has prayed, whether three or four? So he should perform two prostrations while sitting (in tashahhud)."
And the command to perform the two prostrations of forgetfulness is mentioned in a brief report, not a detailed one. Many of those who cannot distinguish between what is explained and what is general, and do not understand the brief and the detailed reports, may think that the one who is doubtful in his prayer is allowed to end his prayer upon doubt after performing the two prostrations of forgetfulness.
Hadith Referenceصحيح ابن خزيمه / جماع أبواب السهو فى الصلاة / 1020