It is not essential to form the intention (niyyah) of offering the prayer that is currently due or of making up a prayer that has been missed
Question

If I am praying Zuhr and the adhaan is given for ‘Asr when I have not completed the first rak‘ah, do I have to repeat the prayer, because the intention has changed from offering the prayer that is currently due to making up a prayer that has been missed? What if I prayed Zuhr on the basis that it was the prayer that was currently due, and I did not realize that the time for it had ended? Should I also repeat it, because my intention should have been to make up the prayer (qadaa’)?
Praise be to Allah.Firstly:
It is not permissible for a Muslim to delay the prayer until the time for it ends, without an excuse. If someone fails to pray before the time for the prayer ends, without an excuse, then he has committed a grave sin. What he must do is repent to Allah, may He be exalted, and resolve to always offer the prayers on time.
In the case of one who delays the prayer until the time for it ends because of an excuse, such as falling asleep or forgetting, he must offer the prayer once that excuse no longer applies. For more information, please see the answer to question no. 20882.
Secondly:
In the case of the prayer that is currently due, it is not stipulated that one form the intention (niyyah) to offer that prayer. By the same token, it is not stipulated when making up a missed prayer that one form the intention of making it up (qadaa’), especially if the reason why you missed it was falling asleep or forgetting, because in that case you are offering the prayers at the right time.
Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him) said:
If someone falls asleep and misses a prayer, or forgets it, then in his case the time for that prayer is when he wakes up or when he remembers it. At that time, he is enjoined to offer that prayer, and there is no other time for it except that time, so he is offering it at its proper time.
End quote from Majmoo‘ al-Fataawa (24/57).
It says in Mirqaat al-Mafaateeh (2/312):
With regard to offering a prayer that a person was distracted from or forgot, or slept and missed it, when he remembers it is the right time for offering that prayer, even if it is after the time prescribed for that prayer has ended, because when he remembers it or wakes up is the time to offer it. End quote.
It says in al-Mawsoo‘ah al-Fiqhiyyah al-Kuwaitiyyah (42/84-86):
The fuqaha’ are of the view in general that it is not essential to bring to mind whether the prayer is one that is currently due or a missed prayer that is being made up when intending to pray. However, there was some further discussion and some differences of opinion concerning this matter.
The Hanafis – as was narrated by Ibn Nujaym – said that if he brings to mind the name of the prayer that he is going to offer, that is valid, whether he formed the intention of offering the prayer that is currently due or of making up a missed prayer. Fakhr al-Islam and others said in al-Usool fi Bahth al-Adaa’ wa’l-Qadaa’: Either of them may be used in the place of the other, so that it is valid to offer a current prayer with the intention of making up a missed prayer, and vice versa.
The Shaafa‘is said: With regard to offering a current prayer or making up a missed prayer, there are many views… The soundest of which is the fourth view: It is not essential to specify either of them in his mind, because ash-Shaafa‘i stated that the prayer of one who is praying on a cloudy day is valid, after he thinks and works out whether the time is due or not; and the fast of a captive is valid, if he intends to fast and then they realize [in each of these two cases] that it was not as they thought.
The Hanbalis said: It is not essential to bring to mind whether the prayer is the prayer that is currently due or a prayer that is being made up, and it is not stipulated that the intention be brought to mind that one is offering the prayer that is currently due. End quote.
Based on that, your prayer as described in the question was valid, and you do not have to do anything else.
But you must repent and seek forgiveness for delaying the prayer until its time ended, and you should keep offering all the prayers on time, and indeed in the mosque with the people where the call to prayer is given.
You should also do a lot of naafil (extra) prayers, to make up for any shortfall in the obligatory prayers, as we have explained in the answers to questions no. 90143 and 147624.
And Allah knows best.