The point is that it may or may not be wrong, but that in certain situations a potentially “immoral” action shouldn’t be illegal
Partly because it’s hard for society to agree on what’s right and wrong (even though some things are definitively right or wrong). And partly because law will not always handle these questions in a fair/just way.