It's even more related to the fact that you set up a guard squad in the first place. Don't do that unless you want them attacking your dwarves. It's their job, that's what they do.
What happens is that a noble (mayor, baron, count, etc.) says "I want 3 fine pewter items made". You either don't notice the announcement, or don't have the correct materials, so you don't make them. Then after a few months, the noble gets upset and blames a random craftsdwarf for not making them. The guards observe that there is no jail, so they find the poor victim unrepentant criminal and beat him up. And if your guards are equipped with spears (or axes, or swords, or hammers, etc.), they probably kill him. Justice (such as it is) is served.
Or even worse is when you have just traded away several dozen rock mugs, the trading caravan has left your fort and is halfway to the edge of the map, and your baron suddenly decides to forbid the export of mugs. The traders leave the map with the mugs and your baron is livid that his export ban was violated, so every dwarf that carried a mug to the trade depot is now charged with the crime.
This is why I almost never assign a Captain of the Guard. The justice system as it currently works is just too arbitrary, random, unavoidable, and brutal. Assign a militia commander instead. His troops' job is to beat up goblins and other foreigners, not your dwarves.