So while modern legal and ethical codes aren't necessarily appropriate, neither should those of medieval Europe necessarily be assumed either...D&D is played by players living in the modern world - be that the USA, Scotland, or elsewhere. That means that the players are going to bring a whole load of assumptions to the game, some of which they may well not even realise are assumptions. And they're not wrong to do so.
I'm going to quibble with "And they're not wrong to do so.", since this point seems to contradict the first one. At the very least, they should be expecting that a quasi-feudal, quasi-frontier fantasy world should not conform to modern assumptions about law and order. They probably should also expect that modern moral and social sensibilities aren't necessarily in place either. That isn't to say that they can't bring their assumptions that the modern ways and moral beliefs they actually hold and think them superior to what actually is there, but it does mean that they shouldn't expect it to be a world in broad alignment to modernity or even a particular epoch of history. Expecting to be surprised should be the expectation, and when in doubt they should ask questions: "Do they have newspapers?", "How do you go about advertising?", "Would people find it odd if I wasn't religious?", "What is the normal legal stance on homosexuality/women's rights/abortion/democracy/freedom of speech/right to bear arms?", "Do nominally good people tolerate or even approve of slavery/the death penalty/sex out of marriage/charging interest on a loan/capitalism/colonialism/etc.", "Is it ok for nominally good people disagree over these things, or is there general 'word from on' high by all the lords of heaven?", "Are orcs considered people or monsters, and more to the point is it ok to just kill monsters even if they are sentient, and if so how do people justify that morally?", "Is casting an evil spell ok if you do it for a good reason, or is it always evil?"
Different settings and DMs are going to have very different answers. For that matter, you can't even assume uniformity of opinion on all that among 'modern people', so it's dangerous to assume anything.
I have at least three purposes in having 'alien' laws.
1) First, I want to raise big red flags on any player that may have unquestioned assumptions about how things work. I try to never play 'gotcha', but sometimes players tell me what their characters do while keeping in their heads an unstated assumption about what they want to accomplish and its only after they've gone a certain ways down a plan that I realize they've been making assumptions.
2) Secondly, I really don't want it to just feel like a pastiche of the modern world, or worse a pastiche of the modern world with anachronistic medieval elements. I want the setting to feel a bit alien, especially at first. I want it also to feel logical, which pastiche's of the modern world seldom do in a world with magic, monsters, multitudes of alien creatures and strange and often questionable technological development.
3) Thirdly, particularly with the laws regarding magic and the like, I want to very much impress on the PC's from the beginning that if the use their powers to 'fool around' with NPCs thinking that it's funny and generally try to bully NPCs, the NPCs aren't likely to think it very funny and just sit back and take it. Casting charm person on the barmaid to try to get her to sleep with you, or casting charm person on the merchant to try to get free stuff won't be treated as an amusing joke.
There is a general rule of the world I'm trying to convey to players that they aren't nearly as clever as they think they are, and that any obvious thing that they would try - like using an illusion to turn copper coins to gold, or using enchantments to make a merchant want to give you all his stuff - are things that are more ordinary and understandable of crimes as identify fraud or writing bad checks are in this world. One thing that almost all 'zombie apocalypse' movies have in common is they occur in worlds where there isn't a lot of 'zombie apocalypse' fiction, so that when the zombie apocalypse breaks out everyone is baffled what to do about it. Likewise, in vampire fiction set in this world, when the vampire shows up, no ones mind first leaps to vampires except maybe that one guy in the know. But this is a world where vampires and zombies and magic is all ordinary to them as cars and the internet are to us. When a door opens by itself, no one in this world is baffled and thinks, "Maybe I didn't shut it and the wind blew it open." They think, "Gods help me, something invisible just walked into the room.", and even if it's just a 6 Int commoner, he know at least much about what to do about it as your average modern person knows about the weaknesses of fictional vampires. One of the most frustrating things to me as a DM is players that assume that because their powers are new to them the player, that they are new and novel to the setting as well. Equally bad is the player that thinks that they are armed with special knowledge and are just going to upset and overturn everything.
"No, seriously, the army is trained to deal with fireball. Every professional army on the planet recognizes a guy in a robe waving a twig around is potentially dangerous, in the same way a modern professional army would recognize a guy with an RPG launcher."
"Believe it or not, they build castles armed with the knowledge of what a 6th level wizard can do."
"Believe it or not, you can't overturn the entire economy by using a simple spell."
"Believe it or not, you aren't the first person who has tried to invent a firearm and equip an army with it, and the reason you don't see armies of guys with muskets isn't because people are stupid and haven't thought of it."
"Believe it or not, in a world with dragons flying around and similar hazards, cities generally are capable of reasonably defending themselves against mid-level PC's and other such hazards."
Granted, this wasn't always true, but it has been true for at least 25 years of my DMing. Society got well ahead of the PCs when I realized I the DM needed to, else my setting didn't make the slightest bit of sense if the PC's could just throw it into turmoil by obvious application of spells.