People who have no scruples about attaining certain goals will use this expression as a way to explain what they’ve done. For them, reaching the goal was all that mattered; the damage that was done to get there is irrelevant. It’s the motto of Machiavellians.
Example: He’s campaigning with illegal funds on the theory that if he wins the election the end will justify the means.