Short Answer
No, the Prophet did not mean it literally when he said that if several people attend a funeral then their prayers for him will be answered. He was only encouraging people to attend and explaining that a large number of people praying for someone is usually an indication of their piety. However, no one besides Allah knows the true state of any person, regardless of whether they are held in esteem or looked down upon by others.
The more sincere and pious people who pray for a person, the more it is hoped their prayers will be accepted. Also, usually the better a person was towards others, the more people will want to attend their funeral prayer, so a large number is usually might be a sign of their righteousness. That is why the Prophet encouraged people to attend the funeral prayer and explained to them the potential result of many people attending. Therefore, although a large number of people attending a funeral prayer and praying for the deceased is usually an indication of the righteousness of a person, it is not a definitive sign, since there may be people who outwardly feign piety and have many superficial supporters. Furthermore, it is wrong to think that anyone who had only a few people attend their funeral prayer was a bad person or that they will not be forgiven by Allah. Many righteous people had only a few people attend their funeral prayer due to various reasons.
What the Qur’an and Sunnah Say
The Prophet said, “If a Muslim dies and forty people, who do not associate any partner with Allah, attend his funeral prayer, then Allah will accept their intercession for him.” [Muslim #948]
Version 0.25
Shaykh Mustafa Umar