Praise be to Allaah.
It is permissible for a Muslim to attend a kaafir’s funeral if the kaafir is a relative, such as a mother, father, brother or other relative, but it is not permissible to join in the prayers or any other rites of their religion.
Zakariya al-Ansaari (may Allaah have mercy on him) said: “He may (i.e., it is allowed for the Muslim and is not makrooh) attend the funeral of a kaafir relative, because of the report narrated by Abu Dawood from ‘Ali who said, ‘When Abu Taalib died, I came to the Messenger of Allaah (peace and blessings of Allaah be upon him) and said, ‘Your uncle, the misguided old man, has died.’ He said, ‘Go and bury him.’” (Reported by al-Nisaa'i, 190). Al-Adhraa’i said: “It is possible that this includes permission to attend the funeral of a wife or slave…”
As for visiting graves, in al-Majmoo’ it says: “The correct view is that this is permissible, and most scholars said this, because of the hadeeth narrated by Muslim in which the Prophet (peace and blessings of Allaah be upon him) said: ‘I asked my Lord for permission to ask for forgiveness for my mother, and He did not give me permission; I asked Him for permission to visit her grave, and He gave me permission.’ It was reported that he also said: “Visit the graves, for they remind you of death.” (Asnaa al-Mataalib Sharh Rawd al-Taalib, part 1, Fasl: Mashiy al-Mashee’ li’l-Janaazah).
One of the differences between going to a Muslim’s funeral and going to a kaafir’s funeral is what was mentioned by al-Mirdaawi (may Allaah have mercy on him) in his book al-Insaaf, where he says in a footnote: “ ‘Those who are walking should walk in front of it [the coffin]’ means that this is better, and this is the madhhab, and this is the opinion of most of the scholars [of that madhhab]. The author of al-Ri’aayah said: “He may walk wherever he wishes.” Al-Musannif said in al-Kaafi: “Wherever he walks, it is OK… and his saying, ‘The riders [should travel] behind’ means that this is better. So there is no dispute in this matter. If he is riding, it is makrooh for him to ride in front.” This is what al-Majd said. What was meant by “the riders [should travel] behind” is that this is how it should be done in the case of a Muslim’s funeral, but if it is a kaafir’s funeral, then the rider may go in front, as mentioned previously.” (al-Insaaf, part 2, Kitaab al-Janaa’iz).
This is provided that attending the funeral does not involve doing anything haraam, such as listening to musical instruments and so on; in that case attending the funeral is haraam. And Allaah knows best.
Islam Q&A
Sheikh Muhammed Salih Al-Munajjid
http://islamqa.com/en/ref/2278