means that
a desirable objective is sometimes used to defend questionable methods of achieving it; the saying expresses a controversial moral position rather than an unquestionable principle.
Imagine a case where wrong or unfair or illegal methods may be used if the result of an action is good.; then “The end justifies the means” fits well.