A Muslim may attend the funeral of a non-Muslim out of respect as long as they do not participate in any of the funeral rituals such as praying or singing hymns. This is because it is unlawful for a Muslim to participate in other religious rituals or to pray for a deceased non-Muslim. A non-Muslim may attend the funeral of a Muslim.
What the Qur’an and Sunnah Say
“Allah does not forbid You to deal justly and kindly with those who did not fight against You on account of religion and did not drive You out of Your homes. Verily, Allah loves those who deal with equity.” [Surah al-Mumtahanah 60:8]
Allah says, “It is not (proper) for the Prophet and those who believe to ask Allah’s forgiveness for the idolaters, even if they are family.” [at-Tawbah 9:113]
Jābir ibn ʿAbdullāh reported: “A funeral passed by and the Messenger of Allah stood up for it, so we stood up with him. We said: ‘Messenger of Allah, it is a Jewish funeral.’ He said: ‘If you see a funeral, then stand up.” [Bukhari #1311]
When Abu Talib died, his son Ali did not want to be responsible for burying him since he did not give up worshipping idols. The Prophet told him to bury him, so he did. [as-Silsilah as-Saheehah by al-Albaani #161]
What the Scholars Said
Imam Ibn Nujaym said: “You may follow their (non-Muslim) funeral from a distance.” [al-Baḥr ar-Rāiq 2:205]
Imam Nawawi said that it is permissible for a Muslim to perform the washing of the dead body, the burial, and to join the funeral procession of a non-Muslim (al-Majmūʿ 5: 89)
If it is likely that you will feel awkward for not joining in the prayers and hymns that occur during funeral rituals, or you will feel pressured to pretend you are praying, then it is better to avoid these gatherings and give condolences to the family privately.