First of all, we should understand the situation the Muslims were in at the time. They were recovering from the battle of Badr, in which, despite having won, muslims faced casualties. The biggest threat however, was within the walls of Medinah. The Jewish tribe of Banu Qaynuqa had recently been expelled for their enmity, despite having signed a peace treaty (Seerah-i Ibn Hisham, volume 2, page 501). Some of you may deny the jews signed this willingly, but there is good reason to believe they initially wanted to ally with the Muslims. The jews had been persecuted by the byzantine empire, and were hoping that an alliance with the muslims, which they shared a lot with, could protect them.
To make sure the other Jewish tribes in the area didn’t get the same idea as the Banu Qaynuqa, they had to be dealt with, and fast. We can clearly see the delicate situation between Muhammad and the jews from another source. Muhammad held a conciliatory speech, a last warning to the jews:
The fate of Quraysh serves them right. It is a lesson to you as well. I am afraid that the same misfortune may overtake you. There are many learned men and religious scholars amongst you. You should verify from them so that they may tell you clearly that I am the Prophet of Allah and that this fact is recorded in your Scripture (the Taurat)".
The Jews replied: "Do you think that we are weak and unaware of the war strategy like Quraysh? You confronted a group who did not know the principles and tactics of fighting. However, the strength of the children of Qaynqa' will become known to you when you meet them in the battlefield".
(Mughazi-i Waqidi, volume 1, page 176 also in Tabaqat-i Kubra, volume 2, p. 39)
Ka’ab took advantage of this fragile situation by inciting the Quraysh to attack the Muslims.
Let’s have a look at Ka’ab and the assassination of him as it was mentioned in early Islamic sources.
Ibn Hisham:
There is also a large hadith in Bukhari which speaks of the assassination. It doesn’t say much about the motive though, apart fromKa’ab said: "Is this true? Did Muhammad actually kill these whom these two men mention? These are the nobles of the Arabs and kingly men; by God, if Muhammad has slain these people it were better to be dead than alive."
When the enemy of God became certain that the news was true he left the town and went to Mecca to stay with al-Muttalib who was married to `Atika. She took him in and entertained him hospitably. He began to inveigh against the apostle and to recite verses in which he bewailed the Quraysh who were thrown into the pit after having been slain at Badr.
Then he composed amatory verses of an insulting nature about the Muslim women. The apostle said - according to what Abdullah Burda told me, "Who will rid me of Ibnu'l-Ashraf?" Maslama said, "I will deal with him for you, O apostle of God, I will kill him." He said, "Do so if you can." So Maslama returned and waited for three days without food or drink, apart from what was absolutely necessary. When the apostle was told of this he summoned him and asked him why he had given up eating and drinking. He replied that he had given him an undertaking and he did not know whether he could fulfil it. The apostle said, "All that is incumbent upon you is that you should try." He said, "O apostle of God, we shall have to tell lies." He answered, "Say what you like, for you are free in the matter."
“Allah's messenger said "Who is willing to kill Ka'b bin Al-Ashraf who has hurt Allah and His apostle?”
So we see clearly, that according to Ibn Ishaq, he incited people against Muhammad. The hadith from Bukhari doesn’t tell us a lot, apart from the fact that Ka’ab has “hurt Allah and Muhammad”. So we can conclude that
1. Ka’ab incited people to kill Muhammad
2. This is clear treason as he was under a peace treaty with Muhammad
3. The situation between the Muslims and the Jews was delicate, and an example needed to be set.
4. And not as important, but worth mentioning; Ka’ab composed hate poems about Muslim women.
From this it can be concluded that the assassination of Ka’ab was not only completely justified, but absolutely necessary as well.
Ishaq also reports “Our attack upon Allah's enemy cast terror among the Jews, and there was no Jew in Medina who did not fear for his life.” While this is regrettable, it demonstrated that unprovoked enmity toward the Muslims would not be tolerated. The assassination did not happen because of criticism of Muhammad.