Because the trait is not the end all be all. It's a random walk to an outcome that leads to enough offspring to survive for the species to be there at all. It's probably not even the most optimal solution whatever is there, just happens to be competitive among the rest of the ecology to not be snuffed out.
You might be interested in this concept:
https://en.wikipedia.org/wiki/Fitness_landscape