Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:9:84

And do not pray ˹the funeral prayer, O Muhammad˺, over any of them who has died - ever - or stand at his grave. Indeed, they disbelieved in Allah and His Messenger and died while they were defiantly disobedient.  

When the Prophet (s) prayed over ˹the dead body of ‘Abd Allāh˺ Ibn Ubayy, the following was revealed: And never pray over any one of them when he is dead, nor stand over his grave, at a burial or as a visit; lo! they disbelieved in God and His Messenger, and died while they were wicked, ˹they died˺ disbelieving.
القرآن:٩:٨٤

وَلَا تُصَلِّ عَلَىٰ أَحَدٍ مِنْهُمْ مَاتَ أَبَدًا وَلَا تَقُمْ عَلَىٰ قَبْرِهِ ۖ إِنَّهُمْ كَفَرُوا بِاللَّهِ وَرَسُولِهِ وَمَاتُوا وَهُمْ فَاسِقُونَ  

ولما صلى النبي ﷺ على ابن أبيّ نزل {ولا تُصلِّ على أحد منهم مات أبدا ولا تقم على قبره} لدفن أو زيارة {إنهم كفروا بالله ورسوله وماتوا وهم فاسقون} كافرون.