Praise be to Allah.
Can you remove major impurity by tayammum?
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., janabah, menses and nifas (postpartum bleeding) according to the majority of scholars. It is also prescribed in the case of minor impurity, according to scholarly consensus. (See: al-Majmu‘ Sharh al-Muhadhdhab by an-Nawawi, 2/207)
The evidence for that is the hadith 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-Bukhari (344) and Muslim (682)
Can you fast in a state of impurity?
Purification is not a condition of fasting being valid. `Aishah 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 major ritual impurity, having been intimate with his wife, then he would do ghusl and fast. (Narrated by al-Bukhari (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.
“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.”(Al-Majmu`, 6/308)
Is prayer without purification valid?
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-Ijma‘ (1) and an-Nawawi in Sharh Muslim (3/102).
What you should have done was to 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 ghusl, 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 janabah.
This view was supported by Shaykh al-Islam Ibn Taymiyah, who said in Majmu‘ al-Fatawa (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-Sahihayn 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 ‘Ammar to repeat the prayer; when ‘Umar became junub he did not pray, and ‘Ammar rolled in the dust like animals do. And he did not instruct Abu Dharr to do the prayers that he had missed when he was in a state of major ritual impurity. And he did not instruct the woman who was suffering from irregular non-menstrual bleeding (istihadah) 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 Companions 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 janabah.”
Shaykh Ibn ‘Uthaymin (may Allah have mercy on him) was asked about a man who did wudu and prayed Fajr when he was in a state of janabah, 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 (istihadah ) who did not pray; and he excused `Ammar ibn Yasir when he rolled in the dust, thinking that this was what was required of him for tayammum. And there are many similar reports.” “Liqa al-Bab al-Maftuh, no. 54)
And Allah knows best.