Hitler was sent to a gentlemen's prison (Festungshaft) for high treason with a sentence of five years, but released after eight months. That is completely ridiculous for high treason. The regular sentence was life, the absolute minimum in case of exonerating circumstances (in this case most likely being right-wing, sorry, "wanting the best for his country") was five years. I'm pretty sure that he would have spent life, or at least many years, in prison if he had been a communist.
Judging by (https://history.stackexchange.com/questions/47780/how-did-hi...) the judge and other were already tilted in his favor, as was the Bavarian state as well.
And it also, kind of worked, from then on Hitler preferred the legal way instead of doing it like Mussolini (i.e. a putsch). It's one part taking the fall for the Ludendorff, one part Bavaria already being sympathetic to him.