Not every superhero, everywhere, all the time, has had a code against killing. Even many superheroes who are famed for their reluctance to kill their enemies have taken a life at one point or another. Some heroes aren't opposed to homicide, per se, at all. For example, Wonder Woman pointedly does not have any compunctions about taking a life (in most versions):
With those superheroes who do have compunctions against murder, the reasoning varies. One common justification is that it's a slippery slope. As vigilantes, they live on the edge, engaging in actions that many would consider morally gray at best. They are always at risk of going too far and intentionally taking someone's life. And then, with their skills or powers, who could say where it would end? Having a strong code of honor prevents this. As Batman says to Superman:
Finally, some heroes have simply opposed killing on absolute moral grounds.
This is Daredevil's reasoning in the Netflix series. From "New York's Finest":
DAREDEVIL: I don't do this to hurt people.
PUNISHER: Yeah, so what is that, just a job perk?
DAREDEVIL: I don't kill anyone.
PUNISHER: Is that why you think you're better than me?
PUNISHER: Is that why you think you're a big hero?
DAREDEVIL: It doesn't matter what I think or what I am. People don't have to
PUNISHER: Come on, Red.
You believe that?
DAREDEVIL: I believe it's not my call, and it ain't yours either.
Notice that Daredevil has two justifications:first, that mentioned previously of opposing directly taking a life on moral grounds. He also exemplifies another common justification (perhaps one of the more realistic): that killing is unnecessary to get his job done. As he says "People don't have to die." He believes that he can stop villains without killing them, and he might be right in the somewhat more realistic world of the MCU (as opposed to Marvel Comics where any supervillain, if not any ordinary criminal, will inevitably be out of prison in short order).
Captain America also has sometimes felt similarly. In this comic, for example, he states that killing is the ultimate violation of freedom:
But, as the previous comic shows, when necessary, he will pick up a gun in order to save lives.
Of course, it all depends on the version of Cap that you're talking about:
So in truth, it is all very dependent on the superhero in question. Many superheroes have no compunction about killing the guilty, and some not even that. Many will kill for utilitarian purposes, even if they generally forgo unnecessary killing.
Among those who do forgo killing, it often is either because it is unnecessary (as is the case with the version of Captain America mentioned previously), or because they fear what they could become if they let their dark side out.