Muhammad already had experience as a warrior before he assumed the role of prophet. He had participated in two local wars between his Quraysh tribe and their neighboring rivals Ban Hawazin. But his unique role as a prophet-warrior would come later. After receiving revelations from Allah through the angel Gabriel in 610, he began by just preaching to his tribe the worship of One God and his own position as prophet. But he was not well received by his Quraysh brethren in Mecca, who reacted disdainfully to his prophetic call and refused to give up their gods. Muhammad's frustration and rage became evident. When even his uncle, Abu Lahab, rejected his message, Muhammad cursed him and his wife in violent language that has been preserved in the Qur'an, the holy book of Islam: "May the hands of Abu Lahab perish! May he himself perish! Nothing shall his wealth and gains avail him. He shall be burnt in a flaming fire, and his wife, laden with firewood, shall have a rope of fiber around her neck!" [111:1-5]
Ultimately, Muhammad would turn from violent words to violent deeds. In 622, he finally fled his native Mecca for a nearby town, Medina, where a band of tribal warriors had accepted him as a prophet and pledged loyalty to him. In Medina, these new Muslims began raiding the caravans of the Quraysh, with Muhammad personally leading many of these raids. These raids kept the nascent Muslim movement solvent and helped form Islamic theology - as in one notorious incident when a band of Muslims raided a Quraysh caravan at Nakhla, a settlement not far from Mecca. The raiders attacked the caravan during the sacred month of Rajab, when fighting was forbidden. When they returned to the Muslim camp laden with booty, Muhammad refused to share in the loot or have anything to do with them, saying only, "I did not order you to fight in the sacred month."
But then a new revelation came from Allah, explaining that the Quraysh's opposition to Muhammad was a worse transgression than the violation of the sacred month. In other words, the raid was justified. "They question you, O Muhammad, with regard to warfare in the sacred month. Say: warfare in it is a great transgression, but to turn men from the way of Allah, and to disbelieve in Him and in the Inviolable Place of Worship, and to expel His people from there, is a greater sin with Allah; for persecution is worse than killing" (2:214,217). Whatever sin the Nakhla raiders had committed was overshadowed by the Quraysh's rejection of Muhammad.
The general principle which Muhammad took from this particular incident was this: to launch a military attack during the sacred month of ceasefire is OK, if you're killing people who have rejected Muhammad's ideas.