Of course a trait can be beneficial in some environments, and harmful in others.
One may also recall the fat years and the lean years from Pharoh’s dream in Genesis: During the fat years, all the mutations can survive, and life prospers, a trait that out breeds the competition provides an advantage. A trait that outbreeds the competition may have an opportunity to get more mutations: (1000 animals will see more mutations than 5 animals).
During the lean years, many die. Animals with packages of mutations or that can not adapt their behaviors to live do not survive, or perhaps even die out without issue.
Of course that requires believing in occasional global warming without insisting that humanity causes it. Since weather is chaotic and can bifurcate at any time, that is reasonable from this side of the keyboard.
Or G-d might have buried fossils in the ground to fool us, as a cunning ploy to guide us to oil deposits.
You missed the point. If mutations occur because of a particular tendency to mutate, then a species will develop traits that are harmful in all environments.
You appear to be hooked on the "all evolution must be good" kool-aide.
There is no evidence that mutations survive because they are beneficial, there is only the fact that mutations survive because they aren't bad enough to terminate the species.
You should question more of what you have accepted as fact.
I return to the giraffe. There are no short species of giraffe, despite an abundance of ground level food that has kept numerous other competing species around during the same period of time that the giraffe mutated. There are tons of negatives to the giraffe's structure. So why would we think it evolved in order to survive? Far more logical to conclude that it evolved due to a one-way tendency of a given gene to mutate, and the species has survived inspite of the mutation, not because of it.