סִימָן קפד – הִלְכוֹת נִזְקֵי הַגּוּף
184: Laws of Bodily Injury
A person is prohibited from hitting his friend, and if he does hit him, he violated a prohibition. As it says, “If” the court “must give the wicked person lashes, [the judge will knock him down and whip him before him according to his evil in number.” A maximum of under “forty times you shall hit him, no more; [lest you exceed hitting him for these, a great smiting, and your brother will be ashamed before you].” (Devarim 25:2-3) If the Torah was careful with the corporal punishment of someone evil that he should not be hit more than his wickedness [merited], a fortiori with the hitting of a righteous person!
Whomever raises a hand against his friend to hit him, even though he didn’t actually hit him, is called “a wicked person”. As it says, [that Moshe “went out on the 2nd day” from Par’oh’s palace “and he saw two men, Hebrews, arguing,] and he said to the wicked one, “Why will you hit your peer?” It does not say, “Why did you hit?” but rather “Why will you hit?” Even though he didn’t hit him yet, he is still called a wicked person.
Whomever hits his friend, he is excommunicated with an excommunication of the ancients. One does not include him to a minyan of ten for any declaration of sanctity until a beis din releases him from the excommunication, when he accepts upon himself to listen to their ruling.
If someone is hitting him or another Jew and there is no way to save himself or his friend from the hand of his attacker accept by hitting him [the attacker], it is permissible to hit him.