Both the context of the organism in which the mutation occurs, and the environmental context in which it finds itself.
Labelling a mutation 'beneficial' is a very loaded statement.
It might be benficial in one context, but not in another.
The same can be said for some deleterious mutations - they are not always deleterious in all contexts.
For example, a mutation for pyrethroid resistance in whiteflies is only beneficial to the whitefly population when it is useful for surviving heavy insecticide applications. When more effective biological controls are established in greenhouses, the incidence of the resistance gene decreases. This is because it is no longer 'beneficial', but is in fact 'less adaptive' that its pyrethroid-susceptible analogue in the absence of the selection pressure.
Also, we need to remember that many mutations are neutral or functionally equivalent, at least until the population's adaptive topography changes...