Praise be to Allah.
Abu Hurayrah (may Allah be pleased with him) said: I heard the Messenger of Allah (peace and blessings of Allah be upon him) say: “Whoever performs Hajj and does not utter obscenities or commit sin, will come back as on the day when his mother bore him.” (Narrated by al-Bukhari, 1521; Muslim, 1350)
And he (peace and blessings of Allah be upon him) said: “From one ‘Umrah to the next is an expiation for whatever (sins) came between them, and for an accepted Hajj there is no reward but Paradise.” (Narrated by al-Bukhari, 1773; Muslim, 1349)
Hajj and other righteous deeds are means of expiation of sins, if a person does them in the manner prescribed in the Shari’ah.
The majority of scholars are of the view that righteous deeds only expiate for minor sins. With regard to major sins, it is essential to repent. They quote as evidence for this view the hadith narrated by Muslim from Abu Hurayrah (may Allah be pleased with him), according to which the Prophet (peace and blessings of Allah be upon him) said: “The five daily prayers, from one Jumu’ah to the next and from one Ramadan to the next is expiation for whatever (sins) come in between them, so long as you avoid major sins.” (Narrated by Muslim, 1/209)
Imam Ibn al-Mundhir (may Allah have mercy on him) and a group of scholars are of the view that an accepted Hajj expiates for all sins , because of the apparent meaning of the two hadiths quoted above.
And Allah knows best.
Reference: Fatawa al-Lajnah al-Daimah li’l-Buhuth al’Ilmiyyah wa’l-Ifta, 11/13.