Disclaimer: the arguments below are based on general legal principles in use in common law jurisdictions. (NB "Common law jurisdiction" basically means anywhere we Brits exported our laws in the past few hundred years, thereby including the two jurisdictions relevant to the events of Supernatural: the USA and Canada). There may of course be specific rules in a jurisdiction which in particular circumstances may prevail over the application of general principle. Anyone concerned about their legal rights in relation to a specific situation mentioned below should seek legal advice as appropriate from a locally qualified lawyer. No liability can be accepted by the author for any actions taken in reliance on the following opinion.
The first clearly illegal act in the episode is Gary assaulting Sam with a tranquiliser dart and taking over Sam's body.
OK, it's not the first illegal act seen on screen, which is Gary drinking under-age while in Sam's body. But I'm taking you through this in chronological order, OK?
So, the body-swap. When you are talking about misappropriation of personal property (and you can't get much more personal than, well, one's own person), the law has had plenty to say for a very long time. After all, if one's person and one's personal property are not safe from misappropriation, what is?
Let's start with the criminal offence of theft. Gary takes something which belongs to Sam, his body. Gary does this dishonestly, without Sam's knowledge or permission. That's beginning to look like the criminal offence of theft. However, the problem with applying the crime of theft in this situation is that the classic definition of theft includes a further element: an intention on the part of the thief to permanently deprive the owner of his goods. While Gary certainly enjoyed taking over Sam's body, we don't have evidence that he intended it to be a permanent swap, or even that his spell would be powerful to enable it to be a permanent swap. Indeed, Gary's motivation appeared to have been to get close to Dean and to kill him while in Sam's body, presumably with the intention of then returning to his own body which he had left under the bushes in that little public garden. Without any evidence of Gary's intention to permanently deprive Sam of his body, a conviction for theft would be difficult to prosecute.
An easier analogy for a criminal offence in relation to an involuntary body-swap such as Gary's on Sam would be the offence of joy-riding in a motor vehicle, or "taking without consent and driving away" (in English criminal argot this is known as "twoccing"). The essential elements of this offence are the same as for theft, but without the need to prove an intention to permanently deprive. All that is needed is a slight adjustment to the wording of one of the definitions used in the offence: ""motor vehicle" includes "live human body"".
Once the bodies have been swapped, the legal issues become somewhat complicated, and there is a regrettable lack of clarifying judicial rulings. However, one of the benefits of common law is the flexibility it gives the courts to apply existing principles to novel situations.
In relation to criminal law, the essential point to understand is the difference between the doing of an act (known as the "actus reus") and that the act was done with intent ("the mens rea"). "Mens rea" is sometimes called "the guilty mind", but it does not depend on a subjective understanding of guilt or deliberate breaking of the law (although this last can be a relevant factor for some offences). Mens rea simply means that someone deliberately chose to undertake a particular action which constitutes a criminal offence.
Applying the principle of "mens rea" to the body-swap means that Sam himself is not guilty of any of the offences committed by his body while Gary was in charge of it, because there was no conscious decision by Sam to undertake those acts. The analogous situation, already recognised in the common law, is that of the sleepwalker: because there is no conscious act on the part of a sleepwalker, no criminal liability can arise from any actions undertaken by a person while sleepwalking.
On the other hand, it is possible, again working from existing principles, to construct the proposition that Gary is criminally liable for the offences he commits while in Sam's body, as this is analogous to the situation in criminal law where any offence committed by a legal corporation can be the offence of the person in charge of that corporation, on the grounds that the person is what the law calls "the controlling mind". A pertinent example of this principle was set out by the House of Lords in 1956: "A company may in many ways be likened to a human body. It has a brain and nerve centre which controls what it does. It also has hands which hold the tools and act in accordance with directions from the centre. Some of the people in the company are mere servants and agents who are nothing more than the hand to do the work and cannot be said to represent the mind and will. Others are directors and managers who represent the directing mind of the company, and control what it does. The state of mind of these managers is the state of mind of the company and is treated by the law as such."
So using the principle of the "controlling mind", Gary is the one liable for the criminal offences committed while he was in Sam's body. And the offences are numerous. There's theft of the phones which he throws in the dumpster (this counts as an intention to permanently deprive, because Gary is treating the phones as though he owned them, and there is no certainty that they could be retrieved). There's underage drinking at the bar, and theft of Sam's money to pay for it. There's probably criminal damage to Sam' s body by that dominatrix. There's probable rape of Sam's body. (The dominatrix herself may have a defence on both these counts, because she would have reasonably believed that she had been given consent.) And finally, there's the attempted murder of Dean. That's enough, once Gary's back in his own body, to lock that little satanic bastard up for a good long time, even though he is a juvenile.
Sam in Gary's body gets to do very little that the law would be interested in. Sam inadvertently brings out Gary's allergies by eating his mother's toast. He seems to be channelling Dean's table manners here, but there's not going to be any public interest in prosecuting Sam for the actual bodily harm which results. A civil action by Gary for the damage caused would also be unlikely to succeed, given that Sam in Gary's body is acting under an agency of necessity, and that Gary has failed to provide Sam with the appropriate operating instructions and safety warnings. Sam does then turn up to school, which technically might be trespassing. Finally, Sam breaks into Gary's school locker to take the grimoire, which would be breaking and entering and burglary, except that Gary is hardly going to give evidence against Sam, so it would be impossible to prove.
The Lucifer question
The most important long-term legal issue arising from "Swap Meat" is the possibility that Gary in Sam's body could give Lucifer the consent he needs in order to use Sam as his vessel. The demon who comes up with this bright idea seems to have no doubts that it would work, but then it's fairly clear that this is a low-level demon, subject to being summoned by a bunch of school children and having no expectation that an encounter with Sam and Dean would result. Not much reliance needs to be put onto the spur of the moment idea of such a demon. So what is the considered legal position?
The rules regarding angel possession have been repeated a number of times, in "Lazarus Rising," "The Rapture," "Sympathy for the Devil" and "Free to Be You and Me." The essential elements, stated variously by Castiel, Zachariah and Lucifer, are firstly that an angel may only take action on earth when in a human body, and secondly that there must be consent for an angel to possess a human body. That an angel needs a human meat suit is made clear in "Sympathy for the Devil," where Sam is talking to Zachariah and says "Lucifer needs a meat suit?" Zachariah replies "He is an angel. Them's the rules." There is further confirmation later in the episode when Dean says "There's a reason you're telling me this instead of just nabbing me. You need my consent. Michael needs my say-so to ride around in my skin", and Zachariah replies "Unfortunately, yes." Then in "Free to Be You and Me" Lucifer himself sets out the second part of the rule when talking to Sam: "This is your choice. You need to invite me in." Sam states "You need my consent" and Lucifer replies "Of course. I'm an angel."
We have been shown two angel possessions on screen, both of which follow these rules. The first angel possession is shown in flashback in "The Rapture," where Jimmy is talking to a disembodied Castiel: "Promise my family will be okay and I'll do it. Then Yes." We then see Lucifer possessing Nick in "Sympathy For The Devil," where Nick clearly says "Yes". Michael in "The Song Remains The Same" takes possession of John Winchester off screen, but explains it to Dean: "I told him I could save his wife and he said "Yes"". (Interestingly, this may suggest that Dean and Sam may have inherited their ability to be vessels from John, rather than from Mary and her hereditary line of hunters.)
A slight variation on the theme of consent is Anna's rebirth as a child conceived by her human mother. Anna says "My mother, Amy, couldn't get pregnant. Always called me her little miracle. She had no idea how right she was." We don't have sufficient information to fully understand how the rules applied in this situation, as there are a number of possible variables. Perhaps, without her grace Anna was not subject to the usual rule. It's also possible that Mrs Milton's prayers were interpreted as consent, or even that gestation is not possession in the sense meant by the general rule. We don't see or have an explanation of any of the other possessions: Castiel's possession of Claire, or the possessions by Zachariah and his sidekicks, Uriel, Raphael or Gabriel.
The most appropriate legal principle to apply to the crucial question of who can give consent is the constitutional or administrative law rule against sub-delegation. In Latin this is "delegatus non potest delegare". In English, this means that a person who is exercising a delegated power cannot sub-delegate that power to another unless clearly authorized to do so by law. Unpacking the elements of this rule and applying them to the issue of consenting to be a vessel, the first question is "who made the rule?" Given that it is a rule which applies to angels, and limits what they can do, the only possible answer to this is "God". The second question is "to whom is God giving powers?", the answer to which is "each of us as individual human beings, who by giving or withholding consent can control the actions of angels". In this context, it is then sub-delegation if one human being passes on to another human being the right to decide whether or not to consent to the possession of the first human's body.
Using this analysis, there are then good legal arguments to say that in general a sub-delegation of this nature would be unlawful. There is nothing is the rules as currently explained which either constitutes an express grant of authority to sub-delegate or which constitutes a clear indication in the enabling rules which contradicts the general principle against sub-delegation. And further (or in the alternative) there are arguments to say that even if sub-delegation were in principle to be possible, there is no proper sub-delegation in the particular case of Sam and Gary, because Sam has at no point consented to the body swap, and even if he had, did not as part of that body swap expressly authorise Gary to give consent to Lucifer.
A final judicial ruling on this question of consent to angel possession is expected by the end of episode 5.22. Until then, the best available legal opinion (yes, OK, the only currently available legal opinion) is that only the original occupant of a human body may give consent to the possession of that body by an angel. Which leaves only one further question to be answered: Is God a lawyer?