"Even the sense for truth, which is really the sense for security, man has in common with animals: one does not want to let oneself be deceived, does not want to mislead oneself, one hearkens mistrustfully to the promptings of one's own passions, one constrains oneself and lies in wait for oneself; the animal understands all this just as man does, with it too self-control springs from the sense for what is real (from prudence). It likewise assesses the effect it produces upon the perceptions of other animals and from this learns to look back upon itself, to take itself 'objectively,' it too has its degree of self-knowledge. The animal assesses the movements of its friends and foes, it learns their peculiarities by heart, it prepares itself for them."So the virtue of prudence evolves from the animal "sense for truth," which is actually the "sense for security," which is also a "sense for what is real" that supports self-control.
As shaped by evolutionary history, animals must gather information about themselves and about their physical and social environments, and then they must assess that information as it bears upon their needs, so that they can make practical decisions about what they need to do to survive and reproduce. The human moral and intellectual virtue of prudence arises from this pragmatic mental capacity for detecting and responding to threats and opportunities in ways that secure one's well-being.
For social animals, this practical intelligence is largely social intelligence, because the most complex intellectual problem for the social animal is assessing the movements and intentions of one's fellow animals as friends or foes. This can even require "mind-reading"--projecting oneself into the thoughts and feelings of other animals so that one can predict their behavior in alternative scenarios of action in the future.
Some people like Thomas Nagel and Alvin Plantinga see a problem with such an explanation of the human mind as emerging from the evolutionary adaptation of the animal mind. If the mind has evolved as a purely pragmatic instrument for survival and reproduction, then the mind has been designed for practical success but not for true beliefs, because one can imagine that an animal's practical success might come from erroneous beliefs about the world. (In fact, doesn't Nietzsche himself speak of the history of human culture as the history of errors?) If so, then one has no reason to trust the human mind as producing valid knowledge, and thus one has no reason to trust the mind's belief in the theory of evolution. In this way, Nagel and Plantinga argue, an evolutionary naturalism becomes self-defeating.
The only escape from this, they insist, is either the theistic belief (Plantinga) that the human mind can be trusted because it was created in the image of the Divine Mind, or a Platonic belief (Nagel) that the human mind can be trusted because it fulfils a cosmic end or purpose as guided somehow by a cosmic mind.
Nietzsche in the writings of his middle period rejects both positions as lacking any scientific support, and he defends the evolutionary account of the mind as showing how the human mind could arise from animal minds as fallible and yet reliable.
I agree with Nietzsche about this, for reasons that I have elaborated here, here, here, here, and here.