This verse: "Allah grants steadfastness to those who believe with firm word," was revealed in connection with the torment of the grave. It would be said to him: Who is your Lord? And he would say: Allah is my Lord and Muhammad is my Apostle ﷺ, and that is (what is implied) by the words of Allah, the Exalted: "Allah keeps steadfast those who believe with firm word in this world and in the Hereafter."
عَنِ النَّبِيِّ ﷺ قَالَ { يُثَبِّتُ اللَّهُ الَّذِينَ آمَنُوا بِالْقَوْلِ الثَّابِتِ} قَالَ نَزَلَتْ فِي عَذَابِ الْقَبْرِ فَيُقَالُ لَهُ مَنْ رَبُّكَ فَيَقُولُ رَبِّيَ اللَّهُ وَنَبِيِّيَ مُحَمَّدٌ ﷺ فَذَلِكَ قَوْلُهُ ﷻ { يُثَبِّتُ اللَّهُ الَّذِينَ آمَنُوا بِالْقَوْلِ الثَّابِتِ فِي الْحَيَاةِ الدُّنْيَا وَفِي الآخِرَةِ}