Bismillah.
I want you to recall who Abdullah ibn Ubayy was. I want you to read up on him a bit. Here's a few words about him:
Abdullah bin Ubayy was an Ansar chief of Madina. Abdullah bin Ubayy had the ambition to wear the crown of Madina. When the people of Madina invited the Holy Prophet and the Muslims to migrate to Madina and accepted the Holy Prophet as their ruler the designs of Abdullah bin Ubayy were frustrated. As all the Arabs of Madina accepted Islam, Abdullah also became a Muslim as a measure of expediency. Islam, however, sat lightly on him, and he often indulged in activities hostile to Islam.
In the battle of Uhud, he betrayed the Muslim trust and withdrew his contingent at the last moment. On the occasion of the raid of Al-Mustaliq he said unbecoming things against the Muhajreen including the Holy Prophet. In the sad episode of False Allegation he was responsible for calumny against Ayesha. Umar sought the permission of the Holy Prophet to kill Abdullah bin Ubayy, but the Holy Prophet, kind-hearted as he was, did not give the permission.
Even Allah had taken notice of the hypocrisy of Abdullah bin Ubayy, and in a revelation to the Holy Prophet it was said that even if he prayed for the hypocrites seventy times his prayer would not be accepted.
Narrated Ibn 'Umar:
When 'Abdullah bin Ubai (the chief of hypocrites) died, his son came to the Prophet and said, "O Allah's Apostle! Please give me your shirt to shroud him in it, offer his funeral prayer and ask for Allah's forgiveness for him." So Allah's Apostle (p.b.u.h) gave his shirt to him and said, "Inform me (When the funeral is ready) so that I may offer the funeral prayer." So, he informed him and when the Prophet intended to offer the funeral prayer, 'Umar took hold of his hand and said, "Has Allah not forbidden you to offer the funeral prayer for the hypocrites? The Prophet said, "I have been given the choice for Allah says: '(It does not avail) Whether you (O Muhammad) ask forgiveness for them (hypocrites), or do not ask for forgiveness for them. Even though you ask for their forgiveness seventy times, Allah will not forgive them. (9.80)" So the Prophet offered the funeral prayer and on that the revelation came: "And never (O Muhammad) pray (funeral prayer) for any of them (i.e. hypocrites) that dies." (9. 84)
Narrated Jabir:
The Prophet came to (the grave of) 'Abdullah bin Ubai after his body was buried. The body was brought out and then the Prophet put his saliva over the body and clothed it in his shirt.
An interesting commentary on this Hadith here.
There were many reasons behind the Prophet’s leading the janazah prayer of a man who worked hard to divide the Islamic community throughout his life.
The most important reason was to make people who had gathered around him have belief. As a matter of fact, when the Messenger of God was asked why he gave his shirt and why he led the janazah prayer of Abdullah b. Ubay b. Salul, he gave the following answer:
“My shirt and the janazah prayer I performed will not save him from the torture of my Lord. However, I hope that one thousand people from his tribe will become sincere Muslims thanks to them.”
Indeed, one thousand people became Muslims when they saw that the Messenger of God treated Abdullah b. Ubay so graciously.
Read more on his death and the way Prophet (SAW) treated him here.
And for you and me, here's the lesson we must learn from this story:
Wassalam.