Can he avoid attending the funeral of a person who was known to be hard-hearted and cruel?
Question

Can one avoid funeral ceremony of a cruel Person?.
Praise be to Allah.Attending a funeral until the prayer has been offered or until the deceased has been buried is a duty that a Muslim owes to his fellow Muslim. Al-Bukhaari (1240) and Muslim (2162) narrated that Abu Hurayrah (may Allah be pleased with him) said: I heard the Messenger of Allah (peace and blessings of Allah be upon him) say: “The rights of one Muslim over another are five: returning the (greeting of) salam, visiting the sick, attending funerals, accepting invitations and saying ‘Yarhamuk Allah (may Allah have mercy on you)’ to one who sneezes.” 
According to a version narrated by Muslim: “There are five things that a Muslim must do for his brother…” 
Al-Haafiz ibn Hajar said: The apparent meaning is that it is a communal obligation (fard kifaayah). End quote from Fath al-Baari, 3/136. 
So attending funerals is a communal obligation; if some people do it then the rest are absolved of that responsibility, but if none of them do it, then they are all sinners. 
The command to attend funerals is also mentioned in the report narrated by al-Bukhaari (2445) and Muslim (2066) from al-Bara’ ibn ‘Aazib (may Allah be pleased with him) who said: The Prophet (peace and blessings of Allah be upon him) commanded us to do seven things and he forbade us to do seven, and he mentioned: “Visiting the sick, attending funerals, saying ‘Yarhamuk Allah (may Allah have mercy on you)’ to one who sneezes, returning the (greeting of) salam, supporting the one who has been wronged, accepting invitations and fulfilling a person’s oath.” 
Concerning the virtue of attending funerals until the prayer has been offered and the deceased has been buried, the Prophet (peace and blessings of Allah be upon him) said: “Whoever attends the funeral until the prayer has been offered will have one qiraat (of reward) and whoever attends until the deceased has been buried will have two qiraats.” It was said, “What are the two qiraats?” He said: “Like two great mountains.” Narrated by al-Bukhaari, 1325; Muslim, 945. 
However, the Prophet (peace and blessings of Allah be upon him) did avoid offering the funeral prayer for some people, as a punishment and a rebuke, and so as to deter others from doing what they did. He did not offer the funeral prayer for one who had stolen from the war booty, or for one who had killed himself. 
Muslim (978) narrated that Jaabir ibn Samurah said: A man who had killed himself with an arrow was brought to the Messenger of Allah (peace and blessings of Allah be upon him), but he did not offer the funeral prayer for him. 
Abu Dawood (2710), al-Nasaa’i (1959) and Ibn Maajah (2848) narrated from Zayd ibn Khaalid al-Juhani that one of the companions of the Prophet (peace and blessings of Allah be upon him) died on the day of Khaybar. The Messenger of Allah (peace and blessings of Allah be upon him) was told about that and he said: “Offer the funeral prayer for your companion.” The people’s expressions changed (i.e. they did not know why the Prophet (peace and blessings of Allah be upon him) was not going to lead the funeral prayer himself). He said: “Your companion stole from the war booty (when fighting) for the sake of Allah.” We searched his belongings and found some pearls from the pearls of the Jews that were not even worth two dirhams. 
The scholars understood from this hadeeth that the Sunnah is for the ruler not to offer the funeral prayer for one who stole from the war booty or one who killed himself, following the example of the Prophet (peace and blessings of Allah be upon him). 
Here two questions arise: 
1 – Should people of knowledge and virtue follow the ruler’s lead?
2 – Should others who are like the one who stole from the war booty or one who killed himself, or worse than them – such as bandits, oppressors and those who commit major sins or commit sin openly – be treated in like manner? 
The answer is: Yes, people of knowledge and virtue should follow the ruler’s lead, and others who are like the one who stole from the war booty or one who killed himself, or worse than them, should be treated in like manner. 
Al-Baaji said in al-Muntaqa: This is the Sunnah, rulers and people of virtue should refrain from offering the funeral prayer for those who committed major sins, as a deterrent against doing similar actions. The fact that he (the Prophet (peace and blessings of Allah be upon him)) commanded others to offer the prayer for him indicates that they come under the heading of believers and are not regarded as non-believers because of the sins they committed. End quote. 
Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him) said: If a person who did not pay zakaah and did not pray except in Ramadaan dies, the people of knowledge and religious commitment should refrain from offering the funeral prayer for him as a punishment and a rebuke to those who are like him, because the Prophet (peace and blessings of Allah be upon him) refrained from offering the funeral prayer for one who had killed himself, one who had stolen from the war booty, and a debtor who had died without paying off his debt. But some people must offer the funeral prayer for him… If a person who committed sin openly but still had some faith died, like those who commit major sins, and someone refuses to offer the funeral prayer for him as a rebuke to others who are like him, he has done well. If a person offers the funeral prayer for him in the hope that Allah will have mercy on him, and because there is no purpose to be served by refraining from offering the prayer for him, he has also done well. If a person refuses outwardly to offer the funeral prayer for him but makes du’aa’ for him in secret in order to achieve both purposes, that is better than missing out on one of them. End quote. 
Al-Ikhtiyaaraat, p. 80 
In al-Insaaf (2/535), al-Mardaawi narrated that Imam Ahmad did not offer the funeral prayer for those who had committed major sins, and he said: al-Majd (i.e., Majd al-Deen ibn Taymiyah, the grandfather of Shaykh al-Islam Ibn Taymiyah) said that the funeral prayer should not be offered for anyone who had died openly committing sin without having repented. It says in al-Furoo’: and this view is sound. End quote. 
Shaykh Ibn Uthaymeen (may Allah have mercy on him) said: If someone were to say: Shouldn’t this ruling apply to the ameer, qaadi or mufti of every town, anyone whose refusal to offer the funeral prayer would be counted as a rebuke? Does the ruling apply to them? The answer is, Yes, it applies to them. If a person’s refusal to offer the funeral prayer will count as a rebuke, then it is Sunnah for him not to offer the funeral prayer for one who has stolen from the war booty or one who killed himself. 
Then he said: Are those who are like the one who steals from the war booty or who kills himself, or who are worse than them and cause more harm to the Muslims, such as bandits, to be treated in like manner? 
Answer: The well-known view in the madhhab is that they are not to be treated in like manner, 
The other view is that the imam should not offer the funeral prayer for those who are like them, or worse than them, because if sharee’ah prescribes a punishment for a certain sin, then it also applies to sins that are similar or worse than that. 
If the Prophet (peace and blessings of Allah be upon him) did not offer the funeral prayer for the one who stole this insignificant amount from the war booty, then what about one who robs the Muslims on the road, and kills them and takes their wealth? Is he not more deserving of a stern rebuke? 
The answer is, Yes, and that is the correct view: if a sin is equal to these, and the ruler thinks that there is a purpose to be served by not offering the funeral prayer for him, then he should not offer the prayer for him. 
End quote, from al-Sharh al-Mumti’, 5/442. 
Based on the above, if a person was known to be hard-hearted and cruel in the sense that he committed major sins or committed sin openly, then the people of knowledge and virtue, whose refusal will have the effect of deterring others from committing similar sins and will put people off these sins and those who commit them, should refrain from offering the funeral prayer for him. But ordinary people, whose refusal to attend the funeral and offer the prayer will not have any impact, should attend the funeral and offer the prayer, so that they may attain the reward for that and fulfil their duty towards their fellow-Muslim. 
And Allah knows best.