Soundness of the fast of one who is junub
What you should have done, if you were unable to do ghusl, was to do tayammum (“dry ablution”), because tayammum is prescribed for major impurity, i.e., janaabah, menses and nifaas (postpartum bleeding) according to the majority of scholars; it is also prescribed in the case of minor impurity, according to scholarly consensus.
See: al-Majmoo‘ Sharh al-Muhadhdhab by an-Nawawi,, 2/207
The evidence for that is the hadeeth about the man who did not pray with the Prophet (blessings and peace of Allah be upon him). When he had finished praying, he said to him: “O So and so, what prevented you from praying with the people?” He said: I became junub and had no water. He said: “You should use clean earth, for it will suffice you.” Narrated by al-Bukhaari (344) and Muslim (682).
Purification is not a condition of fasting being valid. ‘Aa’ishah and Umm Salamah (may Allah be pleased with them) narrated that dawn would come and the Prophet (blessings and peace of Allah be upon him) would be in a state of janaabah, having been intimate with his wife, then he would do ghusl and fast. Narrated by al-Bukhaari (1926) and Muslim (1109). According to Muslim, it says: “not as the result of an erotic dream”. If that is the case with regard to intercourse, then it applies also to a wet dream and is more appropriate, because intercourse happens by the individual’s choice, whereas he has no choice with regard to a wet dream (i.e., it occurs involuntarily).
The scholars unanimously agreed that the fast of one who is junub because of a wet dream is valid. Al-Maawardi said: The ummah is unanimously agreed that if a person has a wet dream at night and he is able to do ghusl before dawn, but he does not do ghusl and he starts the morning junub as a result of a wet dream, or he has a wet dream during the day, his fast is still valid. End quote from al-Majmoo‘ (6/308).
You made a very serious mistake, which is that you prayed without having purified yourself. Purification from impurity is one of the conditions of prayer being valid according to scholarly consensus, as was narrated by Ibn al-Mundhir in al-Ijmaa‘ (1) and an-Nawawi in Sharh Muslim (3/102).
What you should have done was ask knowledgeable people so that you would not fall into such an error. The ways of asking questions have become easier nowadays, praise be to Allah, and finding out Islamic rulings has become a simple matter that is not difficult for anyone. If you fell short in finding out about the ruling on the matter, then you have to repent to Allah and ask for forgiveness for your sin. If you did not fall short, then Allah will excuse you for your ignorance, by His grace and kindness.
But there was a difference of opinion among the scholars as to whether you have to make up those prayers that you offered without purification, or not.
The most correct view is that this comes under the heading of cases in which one may be excused for ignorance or mistakes, because the person in question was confused on the basis that he was not able to do gusl, so he thought that he did not have to do ghusl, and he did not know that tayammum is an alternative to ghusl in the case of janaabah.
This view was supported by Shaykh al-Islam Ibn Taymiyah, who said in Majmoo‘ al-Fataawa (23/37): With regard to the one who did not know that (some action having to do with the prayer) was obligatory, then as soon as he finds out he should offer the prayer that is due at that time and subsequent prayers (with that obligatory action), but he does not have to repeat any of his previous prayers. It is proven in as-Saheehayn that the Prophet (blessings and peace of Allah be upon him) said to the Bedouin who prayed badly: “Go back and pray, for you have not prayed.” He said: By the One Who sent you with the truth, I cannot do any better than this. Teach me that which will suffice me in my prayer. So he (blessings and peace of Allah be upon him) taught him, and he instructed him to repeat the prayer that was due at that time, but he did not instruct him to repeat prayers that he had offered in the past, even though the man said: I cannot do better than this. By the same token, he did not instruct ‘Umar and ‘Ammaar to repeat the prayer; when ‘Umar became junub he did not pray, and ‘Ammaar rolled in the dust like animals do. And he did not instruct Abu Dharr to do the prayers that he has missed when he was in a state of janaabah. And he did not instruct the woman who was suffering from irregular non-menstrual bleeding (istihaadah) to make up the prayers that she had not done, even though she said: I bleed very heavily and it prevents me from fasting and praying. And he did not instruct those who ate during Ramadan until the white string became distinct from the black string to repeat the fast. When the prayer was first enjoined, it was two (rak‘ahs) by two, then when Zayd migrated, the prayer when not travelling was made four rak‘ahs. In Makkah, Abyssinia and the deserts there were many Muslims who did not know about that until after some time had passed, and they continued to pray two rak‘ahs, but he did not instruct them to repeat the prayers that they had offered. Similarly, he did not instruct those who had been praying towards the abrogated qiblah (Jerusalem) to repeat the prayers they had offered facing that direction before news of the abrogation had reached them.
Then he said: A number of the senior Sahaabah used not to do ghusl after being intimate with their wives if no ejaculation occurred, because they thought that water (ghusl) was for water (emission of semen), until it was proven to them that that ruling had been abrogated. For some of them, it was not proven to them that it was abrogated, and they continued to pray without the purification that is required according to Islam, because they did not know that it was obligatory, and one of them would pray when he was in a state of janaabah.
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) was asked about a man who did wudoo’ and prayed Fajr when he was in a state of janaabah, because he was afraid that he would miss the prayer in congregation. He replied:
The correct view is that if he did that out of ignorance, then he is to be excused for that, as the Prophet (blessings and peace of Allah be upon him) excused the one who prayed badly and did not instruct him to make up past prayers; and he excused the woman who was suffering from irregular non-menstrual bleeding (istihaadah) who did not pray; and he excused ‘Ammaar ibn Yaasir when he rolled in the dust, thinking that this was what was required of him for tayammum. And there are many similar reports.
End quote from Liqa’ al-Baab al-Maftooh, no. 54
And Allah knows best.