A Communal Response to a Criminal

What if punishing the criminal will lead them to further abandon their religion?

העובר על דבר איסור מנדין אותו לאלתר: הגה ומנדין למי שהוא חייב נדוי ואפי' יש לחוש שעל ידי כן יצא לתרבות רעה אין לחוש בכך:

One who willingly violates a prohibition may be excommunicated immediately. The Rama adds that one who is worthy of excommunication should be excommunicated even if that means that, as a result, they will turn to even further evil ways.

ואפילו יש לחוש שע"י כן יצא לתרבות רעה. תמיה לי האי מילתא טובא דהיאך נחוש לאיסור שעושה זה ונביאהו לידי תרבות רעה ח"ו

I am shocked at these words (of the Rama)! How can we focus on the prohibition that this person did if, by doing so, will bring that person to further their evil ways Chas V'Shalom.

תשובה כל ימי אני מצטער על זה כי על כן תפוג תורה ואין כח לכוף את הרשעים ועל זה אני מתפלל בכל יום שלא תארע תלקה על ידי אבל מ"מ אגיד לך דעתי בזה... אם באנו לחוש לזה תתבטל התורה לגמרי כיון שיתפרסם הדבר שבשביל חששא זו אנו מעלימים עינינו מהרשעים בני עולה יוסיפו לחטוא וירבה הגזל והחמס והניאוף וכיוצא בזה ולא מתקיים התורה אלא בשרידים... ואע"ג שכתבתי כל זה להלכה מ"מ יש למנהיג הדור להיות מתון בדברים כאלה לפי שאין כל האנשים שוין ולא כל העבירות שוות הא כיצד אדם שהוא רגיל בעבירו' ובוטח בעצמו בטענתו אין חוששין לו ויהי' מה שיהי' ונעמיד התורה ואם אינו רגיל וקרוב הדבר שישמע ממשיכין אותו בדברים עד שישוב מעט מעט ואין ממהרין להענישו מפני התקלה וכן כל כיוצא בזה והכל לפי ראות עיני הדיין המנהיג ובלבד שיהיו כל מעשיו לשם שמים:

I've been troubled by this question (of whether to excommunicate a criminal) my whole life because there is the possibility of the Torah being diminished and there is no way to force the wicked from their ways and, about this, I pray every day that I should not make a mistake in judgement...Once we concern ourselves with the possibility that the violator will turn further away, the Torah will be annulled altogether, because once it becomes known that out of this concern we turn our eyes away from the wicked, evildoers will continue sinning, and theft, violence, adultery and the like will abound, and Torah will be fulfilled only by a small remnant...While I have written all this as Halacha, nevertheless, the leader of each generation must be very cautious in regard to such matters, because not everybody is the same, and not all sins are the same...A person who is accustomed to sinning and feels confident with himself in his claim, we do not concern ourselves with him, and we uphold the Torah, come what may. But if he is not accustomed, and he will likely listen, we draw him close with words until he returns somewhat, and we do not rush to punish him, because this can lead to negative outcomes...Everything must be done as the judge and leader sees fit, provided that all his actions are done for the sake of Heaven.

What is the view on collective punishment?

הגה ויש רשות לבית דין להחמיר עליו שלא ימולו בניו ושלא יקבר אם ימות ולגרש את בניו מבית הספר ואשתו מבית הכנסת עד שיקבל עליו הדין:

The Rama says that the Jewish Court has the right to impose upon this criminal that his children will not be circumcised, that he will not be given a Jewish burial, to banish his children from their school, and his wife from attending their shul until he accepts his judgement.

לֹֽא־יוּמְת֤וּ אָבוֹת֙ עַל־בָּנִ֔ים וּבָנִ֖ים לֹא־יוּמְת֣וּ עַל־אָב֑וֹת אִ֥יש בְּחֶטְא֖וֹ יוּמָֽתוּ׃ (ס)
Parents shall not be put to death for children, nor children be put to death for parents: a person shall be put to death only for his own crime.