Neither. Necessity is not the justification for taking a life. Who decides what is necessary? You can posit an objective criterion for determining that, but what guarantees will there ever be that those deciding will make the correct evaluation? The Confederate South saw starting the Civil War as necessary for the preservation of their culture, threatened by an oppressive regime sympathetic to Northern culture. The Germans sympathetic to the Nazis considered the persecution of the Jews, war with Britain, and the invasion of Poland as necessary for similar reasons. Arab Muslims consider the annihilation of Israel as necessary to the survival of the Palestinian victims whom they support. Every one of these examples has clear and obvious flaws in the justification, but if you think that the other side is as morally certain of their position as history supposes they should be, I think you'd be very much wrong. Were the Allies right to punish Germany after WWI? Was the North right to destroy the Southern economy by outlawing slavery? Is Israel right to aggressively defend themselves against Hamas while they hide behind their women and children?
As far as your hypothetical cows go (as well as your hypothetical and purely imaginary criminals) living is necessary at almost all costs. At no point would they see their deaths as necessary by any standard. Cow doesn't have to die; people can eat other things. Criminal doesn't have to die; he's incarcerated. The only person who can justify the taking of another life is the person whose life depends upon the life of the other ending. The rest of the world is free to judge necessity. In truth, the justification is that a man has a right to live because he cannot live as a man otherwise. If his life is threatened, he has the right to protect it. Is it because his need to live is above the need to live of those who threaten him? There's a contradiction in your reasoning, and it has been exploited historically in every instance of mass murder that I can recall. Needs of the many vs. the needs of the few. Feel free to interchange that with whatever group you like. Salem witches. Bourgeoisie. Who needs to stay and who needs to go? I imagine it's necessary to the lives of cows that humans die, since we insist upon eating them. Gazelles and lions, flies and spiders, etc. Instinct or not, the prey needs to live and so does the predator.