Answer
Have I invalidated my intention for the prayer and should I repeat it?
✅Answer: Please pay attention to the following narrations:
1 عَنْ مُعَاوِيَةَ قَالَ: سَأَلْتُ أَبَا عَبْدِ اللَّهِ عَنْ رَجُلٍ قَامَ فِي الصَّلَاةِ الْمَكْتُوبَةِ فَسَهَا فَظَنَّ أَنَّهَا نَافِلَةٌ أَوْ قَامَ فِي النَّافِلَةِ فَظَنَّ أَنَّهَا مَكْتُوبَةٌ قَالَ هِيَ عَلَى مَا افْتَتَحَ الصَّلَاةَ عَلَيْهِ.
📚 Al-Tahdhib, Vol. 2, p. 197
Muawiyah ibn Ammar says: I asked Imam al-Sadiq (peace be upon him) about someone who stands for a mandatory prayer (fardh) and then makes a mistake and thinks it is a voluntary prayer (nafilah), or stands for a voluntary prayer and thinks it is a mandatory prayer.
The Imam said: He is upon that which he began and initiated the prayer with!
2 عَنْ عَبْدِ اللَّهِ بْنِ أَبِي يَعْفُورٍ عَنْ أَبِي عَبْدِ اللَّهِ قَالَ: سَأَلْتُهُ عَنْ رَجُلٍ قَامَ فِي صَلَاةٍ فَرِيضَةٍ فَصَلَّى رَكْعَةً وَ هُوَ يَنْوِي أَنَّهَا نَافِلَةٌ فَقَالَ هِيَ الَّتِي قُمْتَ فِيهَا وَ لَهَا وَ قَالَ إِذَا قُمْتَ وَ أَنْتَ تَنْوِي الْفَرِيضَةَ فَدَخَلَكَ الشَّكُّ بَعْدُ فَأَنْتَ فِي الْفَرِيضَةِ عَلَى الَّذِي قُمْتَ لَهُ وَ إِنْ كُنْتَ دَخَلْتَ فِيهَا وَ أَنْتَ تَنْوِي نَافِلَةً ثُمَّ إِنَّكَ تَنْوِيهَا بَعْدُ فَرِيضَةً فَأَنْتَ فِي النَّافِلَةِ وَ إِنَّمَا يُحْسَبُ لِلْعَبْدِ مِنْ صَلَاتِهِ الَّتِي ابْتَدَأَ فِي أَوَّلِ صَلَاتِهِ.
📚 Al-Tahdhib, Vol. 2, p. 343
Abdullah ibn Abi Ya'fur says: I asked Imam al-Sadiq (peace be upon him) about a person who stands for a mandatory prayer, then performs one rak'ah, and the thought passes through his mind that it is a voluntary prayer.
The Imam said: Your prayer is the same as that which you stood up for (in the beginning) and for it!
And he said: If you stood up for prayer with the intention of a mandatory one, and then doubt entered you afterward, then you are in the mandatory prayer, upon that for which you stood. And if you entered the prayer with the intention of a voluntary one, and then you intend a mandatory one from it, then you are in the voluntary prayer, and indeed, for the servant, only that which he began his prayer with is counted!
✅ According to the general principles provided by the Ahl al-Bayt (peace be upon them) in the two narrations above, a person's prayer, in terms of being mandatory, voluntary, and so on, is what they initially stood up for with its intention and purpose. The doubts and mistakes that come to them during the prayer do not invalidate their initial intention for which they stood up for the prayer, and their prayer is the same as that which they initially entered upon.
Therefore, in the question above, if the person, during a three-rak'ah prayer, feels or the thought momentarily passes through their mind that their prayer was four rak'ahs, they do not need to repeat the prayer for this reason, unless they add a rak'ah to their prayer or commit other actions that necessitate repeating the prayer, the rules for which are found in the narrations of the Ahl al-Bayt (peace be upon them).
اللَّهُمَّ فَصَلِّ عَلَی مُحَمَّدٍ وَ آلِ مُحَمَّدٍ وَ عَجِّلْ لِوَلِیِّکَ الْفَرَجَ وَ الْعَافِیَةَ وَ النَّصْرَ