The punishment was given to Jews who violated one of Mitzvah's lo te'aseh bemeizid.
The Malkot originated in Deuteronomy 25:1–3: When people have a dispute, they are to take it to court and the judges will decide the case, acquitting the innocent and condemning the guilty.
If the guilty person deserves to be beaten, the judge shall make them lie down and have them flogged in his presence with the number of lashes the crime deserves, but the judge must not impose more than forty lashes.
If the guilty party is flogged more than that, your fellow Israelite will be degraded in your eyes.
[3] According to Hebrew teachings, Malkot cannot prevent a punishment that is yet to come afterlife.