All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
The funeral prayer is a collective obligation. If some worshippers perform it, the obligation is removed from other worshippers and it becomes a Sunnah (a recommended act) for them.
However, if what motivated you to perform this act of worship was just to avoid the blame of the people or so that they would not have bad thoughts about you, and it was not to seek the reward from Allaah, then this intention is defective and the act of worship is not accepted with such an intention. The Prophet, sallallaahu ‘alayhi wa sallam, said: “Verily, Allaah does not accept a deed except that which is devoted purely to Him and by which His countenance is sought.” [An-Nasaa’i]
Another Hadeeth reads: “There is no reward unless it is sought, and there is no deed without intention.” [Al-Daylami - Al-Albaani graded it Saheeh (sound)]
Al-Munaawi said in Faydh al-Qadeer: “There is no reward unless it is sought, i.e. unless the recompense from Allaah is sought, and there is no act of worship that is taken into account without intention.” [End of quote]
It is not unlikely that your intention was Riyaa’ (to show off) because some scholars included doing an act of worship in order to repel a minor harm in Riyaa’. Bareeqah Mahmoodiyyah reads: “Riyaa’ is not restricted to reputation but it also includes (seeking to obtain) money, or fulfilling one’s desire, or repelling a minor harm.” [End of quote]
Scholars also considered it to be Riyaa’ when a person does an act of worship so that he is not looked upon negatively. For examples, Ibn Hajar Al-Haytami said in Az-Zawaajir (that Riyaa’ includes) “that by demonstrating one's worship, piety, humility or the like, one intends not to be disdained or looked upon negatively.” [End of quote]
Whoever does so should repent to Allaah.
Allaah Knows best.