תני תנא קמיה דרב נחמן בזמן שאדם מצער את אביו ואת אמו אמר הקב"ה יפה עשיתי שלא דרתי ביניהם שאלמלי דרתי ביניהם ציערוני
אמר ר' יצחק כל העובר עבירה בסתר כאילו דוחק רגלי שכינה שנאמר (ישעיהו סו, א) כה אמר ה' השמים כסאי והארץ הדום רגלי
Anyone who transgresses in private, it is as if he pushes aside the feet of the Shekhinah--this is when he can conquer his urge, as is proven in the first chapter of Hagigah.
The Gemara raises a difficulty: And is that so? But didn’t Rabbi Ela the Elder say: If a person sees that his inclination is overcoming him, he should go to a place where he is unknown, and wear black, and wrap himself in black, in the manner of mourners, because he should be ashamed of his weakness, and do there what his heart desires, but let him not desecrate the Name of Heaven in public. This shows that sinning in private is sometimes preferable to the public performance of a transgression. The Gemara answers: This is not difficult. This case, where one who commits a transgression in public has no concern for the honor of his Maker, occurs when one is capable of overcoming his inclination and fails to do so. That case, where it is preferable to sin in private, occurs when one is incapable of overcoming his inclination. He is therefore advised to, at the very least, refrain from desecrating God’s name in public.
Anyone who transgresses a sin in private: Since he is embarrassed by the presence of others to transgress in public, and he transgresses in private, he is acting as if the Shekhinah is not able to see in private, and he is pushing aside the legs of the Shekhinah, as if the legs of the Shekhinah are not on the land, and the verse attests "and the land is the resting place for my legs." About this R. Joshua ben Levi said, "It is forbidden for a person to go four amot standing upright." In several places it says that a person's height is four amot, and this one who goes four amot standing straight up, he acts as if it was his, and there is no room for the Shekhinah, and the verse says, "God's presence fills the whole land."
ויעשה מה שלבו חפץ. לגמרי משמע דמוטב לו לאדם שיעשה חפצו בסתר ולא בפרהסיא ולא כפר"ח דשילהי פ"ק דקדושין (דף מ. ושם) דפירש דח"ו שהיה מתיר לעשות עבירה אלא קאמר ילבש שחורים וילך למקום אחר דלבישת שחורים ואכסנאות משברין לבו ולא יבא לידי עבירה ויוכל לעשות מעכשיו מה שלבו חפץ דודאי אין יצרו מתגבר עליו וסוגיא דשמעתא אינו משמע כדבריו הכא ובריש פרק בתרא דמועד קטן (דף יז. ושם):
And he should do what his heart desires: It seems that this means he should fully do what his heart desires, for it is better for a person to do his heart's desire in private and not in public. This is a different interpretation from that offered by Rabbenu Hananel, who said: "Heaven forbid that we should allow one to transgress a sin. Rather what it means is that he should wear black and go to another place. For wearing black and staying at an inn breaks a person's will, and he will not come to transgress, for his urges will certainly not overcome him." But this passage does not seem to read this.