Praise be to Allah.
These words are innovated. There is no doubt that there is no god but Allah and that nothing will abide forever except Allah, but the fact that it is said in this manner as described in the question is bid’ah, because every way of drawing close to Allah or of worshipping Allah that was not done by the salaf (early generations of Islam) is an innovation (bid’ah). Similarly, saying “Yaa Rahmaan, yaa Rahmaan” at the time of burial is also an innovation.
The Sunnah for the one who follows a funeral procession is to ponder and think about his fate and that he is now walking behind the bier, but one day he will be the one whose bier is being followed as this bier is being followed, so he should ponder his own deeds.
At the time of burial, when the burial of the deceased was finished, the Prophet (peace and blessings of Allah be upon him) would stand at the graveside and say: “Pray for forgiveness for your brother and ask for him to be made steadfast, for now he is being questioned.” This is what is prescribed in Islam. End quote.
Shaykh Muhammad ibn ‘Uthaymeen (may Allah have mercy on him).