The gemara quotes a braisa that gives beis din the power to punish even against din torah, meaning to impose stricter punishments than the Torah demands for specific violations, if it is done in a time and place when people are being lax about this issur and the breach must be fixed. The braisa quotes some examples. A. Someone was stoned on shabbos for riding a horse which is only a Rabbinic violation. B. Someone was given malkus for having relations with his wife in public under a fig tree. C. The Mishna says that R. Shimon Ben Shetach judged 80 witches on one day, and hanged them (even though women are generally not hanged) because women were very involved in keshafim. The Rambam (Sanhedrin 24:4) adds that R. Shimon Ben Shetach was lax about the d'risha v'chakira (cross examining the witnesses against the witches) and killed them without them being warned, and without meeting the requirements of witnesses. It is not clear how the Rambam knows that R. Shimon Ben Shetach was lax in so many areas. Perhaps he learns it from the story that is quoted by rashi on 44b where the beis din accepted false witnesses against his son, indicating that it was a midah k'neged midah for R. Shimon Ben Shetach being too lax in accepting witnesses.
There seems to be a machlokes Rashi and Rambam regarding the interpretation of one line in the braisa. The braisa says - ולא לעבור על דברי תורה אלא כדי לעשות סייג לתורה. Rashi explains that when the beis din imposes a stricter punishment than is mandated by the Torah, they are not allowed to intend to violate the Torah and create new punishments that the Torah doesn't require. They can only impose these punishments with the mindset of הוראת שעה and making a s'yag l'torah. Although the Rambam (halacha 4) agrees with rashi in principal and writes that they cannot establish this to be a halacha for generations, it seems to me that he has a different reading of this line. The Rambam (halacha 10) writes:
כל אלו הדברים לפי מה שיראה הדיין שזה ראוי לכך וכו' ובכל יהיו מעשיו לשם שמים, ואל יהיה כבוד הבריות קל בעיניו שהרי הוא דוחה את ל"ת של דבריהם וכ"ש כבוד בני אברהם יצחק ויעקב המחזיקין בתורת האמת שיהיה זהיר שלא יהרס כבודם, אלא להוסיף בכבוד המקום בלבד, שכל המבזה את התורה גופו מחולל על הבריות והמכבד את התורה גופו מכובד על הבריות, ואין כבוד התורה אלא לעשות על פי חוקיה ומשפטיה
The Rambam writes that Beis Din shouldn't jump to impose harsh punishments beyond the Torah's requirements, because they must take the kavod ha'briyos aspect very seriously, especially since this isn't just a creature of Hashem, but a descendant of the avos. The only reason that they are allowed to do this is because the kavod of Hashem trumps their personal kavod. Why? Because one who degrades the Torah is inherently degraded and loses stature in the kavod habriyos spectrum, therefore it is more essential to restore the honor of the Torah than be concerned for his personal honor.
Where does the Rambam get this from? The Kesef Mishneh says that these are the words for the Rambam and they are fit to be said by him. This implies that the Rambam has no source for this approach. I would like to suggest that the Rambam actually reads this into the braisa. When the braisa says - ולא לעבור על דברי תורה אלא לעשות סייג לתורה, the Rambam interprets that the issur of kavod habriyos which is a violation of the Torah, can only be violated for the sake of making a s'yag l'torah, meaning restoring the kavod hatorah to its place.