The danites were organized to defend mormons after all the house burnings and murders commited by the mobs. You need to read the history of the danites in the lds church. Joseph Smith was not happy with them because of their excesses. However, without the persecutions the mormons experienced, there would be no danites.
Background
The Danites were a brotherhood of church members that formed in Far West, Missouri in mid-1838.
By this point in time, the Saints had experienced serious persecution, having been driven out of Kirtland by apostates, and driven out of Jackson County by mobs. Sidney Rigdon was publicly preaching that the Saints would not tolerate any more persecution, and that both apostates and mobs would be put on notice. The Danite organization took root within this highly charged and defensive environment.
The Danites are sometimes confused with the “Armies of Israel,” which was the official defensive organization that was tasked with defending the Saints. This is complicated by the fact that members of the Danite organization also served in the “Armies of Israel.”
en.fairmormon.org/Danites
Notice how the apostates drove the saints out of kirkland. It is usually the apostates that become the greatest enemy of the lds church. It is hard for them to reconcile their apostacy. Not much as changed since that time. But not all apostates becomes enemies. But that few that do, attempt to sow trouble for the lds.