It means that even if the result of your action is good, if the action was bad, it doesn't get a pass just because the end result is good.
For instance, if you steal a million dollars from a bank, then donate the money to charity, you can't justify the good works the charity does with the stolen money to excuse the stealing. Stealing is still wrong.
https://www.quora.com/What-does-the-end-doesnt-justify-the-means-mean/answer/Margaret-Plotkin