Shaykh Abdu-Razzaq bin Abdul-Muhsin al-'Abbaad writes concerning the hajj in his book Min Madrasatu-l-Hajj
It is often that Allah commands for istighfaar, especially at the end of acts of obedience and upon completion of worship.
Allah the Most High says:
ثُمَّ أَفِيضُواْ مِنْ حَيْثُ أَفَاضَ النَّاسُ وَاسْتَغْفِرُواْ اللّهَ إِنَّ اللّهَ غَفُورٌ رَّحِيمٌ
and surge onward together with the multitude of all the other people who surge onward, and ask God to forgive you your sins: for, verily, God is much-forgiving, a dispenser of grace.
And the surge mentioned in the verse here is in reference to the return towards Mina where the Hujjaj stay during the days of hajj. And Allah ordered them to do istighfaar so that it patches up any mistakes or short comings that might have occured.
Similarly it was from the practise of the Prophet to end his good deeds with istighfaar. It is authentically narrated in Saheeh Muslim that the Prophet used to say upon finishing salah, astaghfirullah three times. Even at the end of the night prayers he used to end it with istighfaar.
Allah the Most High said:
وَالْمُسْتَغْفِرِينَ بِالأَسْحَارِ
and [those who] pray for forgiveness in the early morning.
And he used to conclude his sittings with istighfaar as has been authentically reported by Aboo Dawuud on the authority of Abee Burzah al-Aslamee that whenever the Prophet wanted to end a sitting he used to say:
SubhaanakAllahuma wa Bihamdika ash-Hadu an laa ilaaha illa ant astaghfiruka wa atuubu ilayk
The Prophet even ended his life with Istighfaar as has been narrated by Imaam Bukhaaree in his saheeh on the authority of 'Aishah. During his last days in this world whilst being in the care of his beloved wife 'Aishah she heared him repeating.
Allahuma ighfirlee warhamnee wa alhiqnee bi rafeeqil 'ala
O Allah forgive me and have mercy upon me and make me join the company of the noble ones!