The destruction of idols by the Holy Prophet (pbuh & his family) and Imam Ali (a) happened at the last stages of the propagation of Islam and conveyance of its message; this act of the Prophet (s) and Imam Ali (a) was a war launched against one of the most important manifestations of deviation and polytheism i.e. the idols.
Basically, the prophets and divine messengers were sent to eradicate false beliefs and to replace them with divine values and beliefs. Hence, this divine mission required the destruction of the idols by the Prophet of Islam (s) and the Commander of the Faithful, Imam Ali (a), idols that were the manfiest expressions of polytheism. On the other hand, these idol worshippers, who left no stone unturned to hurt and torment the Prophet (s) and Muslims, belittled the Muslims and exposed them as well as their property to danger.
Propagation, warning and guidance are some important aspects characteristic of Islam. The Prophet of Islam (s) was commanded to deliver the divine message and to give people warning about the consequences of worshipping idols. The Quran says: "Arise and deliver thy warning! And thy Lord do thou magnify!" The divine prophets and messengers especially the Prophet of Islam (s) were sent to eliminate false beliefs and to replace them with divine values and beliefs. However, it is necessary to know that Islamic teachings are of two kinds: Individuals teachings and social teachings.
Guidance and propagation of social teachings and establishment of their principles in society require certain stages and measures one of which is to fight deviations. The Holy Prophet (peace be upon him and his family) and Imam Ali (a)'s throwing the idols out of the Ka'bah is a combat act against idolatry. They did so after explaining them (pagans) the truth and showing them proofs about the wrongness of idolatry. They threw out the idols because in a monotheistic system, Ka'bah was not a place for those idols. The Holy Prophet (s) was fully aware of the enemies' deviating propagations; he used every opportunity to eliminate them. According to the Holy Prophet (s), playing with the feelings of people to provoke them against the truth was very dangerous and an unforgiveable sin.
Prophet Ibrahim (a) fought against idolatry using all ways but his sayings and actions had no impact on the miserable unbelievers. On the other hand, Nimrud kept entertaining people to maintain his rule and kingdom; he never wanted them to give up worshipping idols. It was for the same reason that the pagans did not pay heed to Prophet Ibrahim's extortions. Ibrahim later adopted a more serious strategy against idolatry. He warned decisively about not giving up idolatry but they still took these warnings for a jest. Finally, Prophet Ibrahim broke all the idols to pieces except the biggest one which he left standing so that he could blame the enemies using it and to eventually prove to them the righteousness of worshipping the One God.
The destruction of idols by the Holy Prophet (s) and Imam Ali (a) happened at the last stages of the propagation of Islam and this act of the Prophet (s) and Imam Ali (a) was a war waged against one of the most important manifestations of deviation and polytheism i.e. the idols. Moreover, these idol worshippers, who left no stone unturned to hurt and torment the Prophet (s) and Muslims, belittled the Muslims and exposed them as well as their property to danger. However, the Holy Prophet of Islam (s) forgave all of them in the wake of the conquest of Mecca. He ordered the idols to be destroyed and the pagans' becoming angry or getting hurt could not be a reason for not breaking the idols.
For further information, see the following indexes:
1. The Initiator of Idolatry in Mecca, question 2446 (site: 2574).
2. The Motive behind Worshipping the Idols, question 4138 (site: 4413).