Sayyiduna Ibn Abbas (may Allah be pleased with them both) said: The Noble Prophet (peace and blessings be upon him) said: "Hudud (prescribed punishments) should not be carried out inside the mosque, nor should a father be punished in retaliation for his son."
Brief Explanation
(Commentary on Hadith 2393)
Two issues are mentioned in this hadith: First, that a father is not to be killed in retaliation for his son.
Second, that the prescribed punishments (hudud) should not be carried out inside mosques, because this would result in shouting and commotion within the mosque, and there is also the risk of the mosque becoming impure due to blood and the like. The mosque is solely for prayer, recitation, worship, knowledge, and judgment.
Beating and administering punishment are not appropriate in the mosque; for this reason, the Commander of the Faithful, Sayyiduna Umar ibn al-Khattab and the Commander of the Faithful, Sayyiduna Ali ibn Abi Talib (radi Allahu anhuma) would carry out the hudud outside the mosque.
This practice continues to this day in the lands of the Haramain.