Let's assume an algorithm A will always chose the most ethical course of action. If it faces situation A, it will recommend X. In situation B, it recommends Y.
Now, say a company is facing situation A but a malevolent actor replaces the inputs, which say A, for inputs that say B. The algorithm will promptly answer Y. Its answer was completely ethical to the inputs it got yet wrong for the company, since the inputs were tampered.
That's why being ethical does not solve this issue, although it might make it less worse. The ethical thing given the wrong data might not be ethical given the right data.
Hope this clarifies things.