Consider two otherwise identical worlds, in one of which determinism is true, and in the other of which it is not. In the second world there is freedom of the will. What difference does this make to the legal system and the moral system? Ex hypothesi, none. When I wrote that if hard determinism is true, moral systems cannot be corrupt, I was describing Stephen's view, not my own! Hence I think the apparent contradiction that he detects. Here's another way of putting the point I wanted to make. We can imagine a deterministic world in which people are thinking good thoughts and doing good things, and making good laws. The world of law and morality seems to have survived the loss of freedom! In this world, some philosophers believe in determinism, and some in freewill. But of course the having of those beliefs is part of a deterministically produced system. There could be incidentally be a deterministic world that is morally and legally better than a world with freewill. Consider the worst world imaginable, but having freewill, and the best world imaginable, but lacking freewill. You might prefer to live in the unpleasant world, but that doesn't mean it's better. In it the innocent are tortured, unfairness abounds, and so on.
a great question -- a deep one, and an old one -- basically grounded in the classic theistic question addressed by Plato (in Euthyphro) and many others since -- does God command us not to do things (such as murder) because they're wrong, or are they wrong (simply) because God commands us not to do them ... Stephen's response is excellent, but I'll offer another angle. Re the first half -- is murder illegal b/c it's wrong -- no doubt those legislators who have illegalized murder are at least partly (maybe primarily/exclusively) motivated by its wrongness (that's the sociological/empirical question) -- but presumably your question is meant to be more general, i.e. not merely restricted to murder, whose 'wrongness' most everyone can agree to (though not everyone). If you were to ask 'of all those things that are illegal, are they illegal b/c they are wrong?' surely for many/most of them the answer would be 'no.' It's illegal to go through a red light, not b/c going thru red lights is morally wrong but b/c the powers that be, in their wisdom, have established various conventions for the smooth/safe running of society, so they've set up traffic laws to that end -- just which legislation is motivated by morality and which by (say) the need for societal conventions is an empirical question -- but no doubt both factors play at least some role in much legislation ... (and other factors as well) ... re the sec on half -- 'is murder wrong b/c it's illegal' -- Stephen is right to stress the fundamental distinction between law and morality, but I'll just add one point -- the case might be made that, in general, it's morally wrong to break the laws of your society (all else being equal) -- so at least PART of the wrongness of murder (perhaps a very small part) would consist in the fact that committing it is to break the laws ... (again, generalizing the topic: running a red light IS probably wrong precisely because it's illegal ...) Now of course there are some important complicated cases -- for example, civil disobedience -- in some cases you might argue it's 'right' to break the law -- if you think the law itself is morally wrong -- but that's handled by the 'all else being equal' clause I mentioned ....
hope that's useful!
You seem to be asking about the legality of switching or declining to switch, in which case your question is best answered by a lawyer rather than a philosopher of law. I'm not sure, but the answer may depend on the jurisdiction. It may also matter whether the person in a position to switch the trolley is legally authorized to be in that position or is, instead, a trespasser or intruder. I'm not suggesting that the answer provided by the law is totally irrelevant to the morally right answer. The law on this issue, if there is any, may reveal the moral attitude that we currently take toward it, which is relevant to some extent.