It's always the solution. The reason a "civilized" world exists is there are people out there who are willing to commit extreme amounts of violence upon others if called for. The credible threat of violence is what puts negotiation and diplomacy on the table. Even something as civilized as a court of law depends on the existence of armed enforcers in order to be respected.
I disagree with the premise that the threat of institutionalized penalty is what causes people to be good. I think the primary cause of good behavior is lack of reason to commit crime (i.e well fed and housed comfortably) as well as culture.
Why else would cities with exactly the same legal systems across the USA have different crime rates?
When we talk about the reason to commit crimes, we're talking about intent, the very first stage of violent crime. That's the part where someone convinces himself that it makes sense to use violence to get what he wants. Of course, the less intent people are on committing crimes, the better. However, at this point, violence is not happening yet.
Violence comes into play during later stages, when the criminal is actually making his move. The purpose of the threat of violence is to convince people that it's in their best interests to behave according to the rules. Warranted use of violence exists to convince criminals that things could end up very badly for them should they choose to escalate the situation.
Violence is what you use to make unwilling people do what you want. Robbers use overwhelming violence to make victims give up their belongings. Cops use overwhelming violence to make the robber surrender to arrest. If someone is being judged in court, what stops them from literally getting up and walking out to freedom? There are police officers there who will violently prevent that from happening.
Greed complicates things.