Does a trial always have to be "according to law"? No.
Being in accordance with the law is not a sufficient condition for a lawful conviction. If an appellate court finds, in the facts of the case before it, circumstances that should amount to a new defence, and if the court then proceeds to recognise and define that new defence, we would expect the court to apply the newly recognised defence to the appeal before it and to allow the appeal against conviction. In such a case the trial was not according to law, in the sense that the defence was not applied, even though at the time of the trial the defence was not recognised and the trial was according to the law as it was then understood to be. Here, the trial although according to law, was defective.
Neither is being in accordance with the law a necessary condition for a lawful conviction. If an appellate court decides that a previously recognised defence has been incompletely defined, and that now, because of the circumstances revealed in the appeal now being considered, an additional matter is an ingredient of the defence, what should we expect the court to do? Should it apply the newly recognised ingredient to the present case and dismiss the appeal against conviction because at trial the defence had not included the new ingredient? Or should it say that the new law applies to future trials, but this one is to be judged according to the old law? Usually, where the substantive law is changed, a defendant has the benefit of whichever version is more favourable to him. So we would expect the appellate court to say that the old law applied to this trial. If the court does the opposite, and says that the new law applied to this trial even though it was then unknown, the court is saying that the trial could result in a valid conviction even though it was not in accordance with the law as it was at the time of the trial. This latter is what happened in R v Gauthier, 2013 SCC 32 (7 June 2013).
At issue in Gautier was whether there had been sufficient evidence at trial to give a defence of withdrawal from participation (what Canadians call abandonment) an air of reality sufficient to require it to be left to the jury. This turned on what the ingredients of the defence were. Fish J, dissenting, shows that the majority have added a new ingredient in relation to aiders and abettors – the taking of reasonable steps to negative the effect of participation – to those that had previously been identified, namely an intention to withdraw, communicated unequivocally to the other participants. Indeed, the majority do not conceal the development of the defence that they are now undertaking: , -.
The majority applied the new ingredient of the defence to the trial it was considering, and held that there was insufficient evidence of the taking of reasonable steps to negative participation: -.
This means that the trial was not in accordance with the law that the Supreme Court was now recognising, but which was unknown at the time of the trial, yet the trial resulted in a valid conviction.
The rule of law requires that the law be ascertainable. This should mean that a person should be tried according to the law as it was ascertainable at the time of the alleged offending. See, for example, PGA v The Queen  HCA 21, discussed here on 30 May 2012 (and referring to Christian v R (The Pitcairn Islands)  UKPC 47 at , R v Rimmington  UKHL 63 especially at , and Rogers v Tennessee, 532 U.S. 451 (2001)).
Another aspect of Gauthier is reliance on inconsistent defences. There is no rule against this, and all defences, whether raised by the defendant or not, for which there is sufficient foundation in the evidence, should be considered: majority at , Fish J agreeing at -. A "sufficient foundation" exists if there is evidence to give the proposed defence "an air of reality", in the sense that the evidence is reasonably capable of supporting the inferences necessary for the defence to succeed: majority at , and Fish J at  ("some evidence upon which a properly instructed jury could form a reasonable doubt").