The answer to that question has gone through several phases in my lifetime. When I was a kid, bad guys were shot dead left and right, and nobody gave them a second thought. Then we got into the idea of rehabilitation, and bad guys were arrested and led away with "Book 'em, Dano" or something similar. When cop/sleuths' personalities began to enter into fiction, we had to deal with the fact that they FELT like killing the really bad guys. For a while there, it became pretty common for the bad guy (or girl, this was the awakening of women's lib) to off himself. You'd see him eyeing the cliff, the building edge, or the ground below the platform and know that he was going to do the Right Thing and jump. These suicidal thugs came along when many people lacked faith in our prison/court system. Arrest wasn't enough to satifsy reader/viewer sensibilities, but it saved the hero from becoming as bad as his object.
The whole "Don't do it, Jim; he's not worth it" era was fun, too. The hero ALMOST took his revenge by killing the very deserving bad guy, but a friend or coworker intervened to keep him on the side of Right.
So the question for writers of crime fiction remains: who deserves to die, who has the right to make the judgment, and what happens after that judgment is made?
LAW & ORDER has had a long run with following crimes from perpetration to adjudication, and audiences seem satisfied with the occasional bad guy who works the system and gets away as long as most are exposed and punished. Other shows, like CSI and NCIS, make the assumption that catching the crook well and completely is good enough to "put him away" and make us all safer. We even have guys like Dexter, who is allowed to kill and get away with it because he does it in a good cause. (You're supposed to ignore the fact that he gets a real kick out of it.)
The nice thing about today's array of sub-genres in crime writing is that you can find your own favorites and stick with them. You want the bad guy stomped to death by hard-soled shoes? It's out there. You want him arrested and put into a high-security cell with 24-hour monitoring? Got it. And if you like, even occasionally, for the bad guy to prevail, that's available too. I bet those noir novels are really popular in prison libraries.