Praise be to Allah.
It was narrated in al-Saheehayn that Abu Hurayrah (may Allaah be pleased with him) said: I heard the Messenger of Allaah (peace and blessings of Allaah 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-Bukhaari, 1521; Muslim, 1350.
And he (peace and blessings of Allaah 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-Bukhaari, 1773; Muslim, 1349.
Hajj and other righteous deeds are means of expiation of sins, if a person does them in the manner prescribed in sharee’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 hadeeth narrated by Muslim from Abu Hurayrah (may Allaah be pleased with him), according to which the Prophet (peace and blessings of Allaah be upon him) said: “The five daily prayers, from one Jumu’ah to the next and from one Ramadaan to the next, expiate for whatever (sins) come in between them, so long as you avoid major sins.” Narrated by Muslim, 1/209.
Imam Ibn al-Mundhir (may Allaah 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 hadeeth quoted above.
And Allaah knows best.
See Fataawa al-Lajnah al-Daa’imah li’l-Buhooth al’Ilmiyyah wa’l-Ifta, 11/13.