I think it might be in his commentary on Parashas Toldos (Chasam Sofer Al HaTorah, Bereishis, Toldos). I've found that the commentary is on Yerushalmi Nedarim 29b (9:1), where it says:
They asked, from where do you have this? He said to them, I was Meïr’s servant both times when he fled, but some say, Rebbi Meïr’s walking stick was in my hand and it teaches me knowledge.
The Chasam Sofer is supposed to have written:
The Yerushalmi implies that a person’s clothing is influenced by the sanctity of its wearer, and one who wears it after him receives that same spirit for better or worse. This is the secret by which a person’s sons wear it after him.
Let's also dive deeper into this subject on why clothing influences the person wearing it.
Rabbi Pesach Eliyahu Falk in his sefer Oz Vehadar Levusha: Modesty: An Adornment for Life writes as follows:
In contrast, bad clothes have a detrimental and injurious effect on their wearer. They diffuse an impurity which is transmitted to the person wearing them. The Chasam Sofer writes that Yaakov, who always only the truth, would have found it very difficult if not impossible to deviate from the truth and say אָנֹכִי֙ עֵשָׂ֣ו בְּכֹרֶ֔ךָ - "I am Esav, your firstborn" (Bereishis 27:19). To help him overcome this difficulty, Rivka advised him to dress in the clothes of his wicked brother Esav.
Rabbi Falk goes on to explain that a person is aware at all times, of the clothes he wears and is reminded by them of the allegiance that is implied by the clothes he wears. If a person wears clothes that are refined, that person is reminded that he/she has undertaken to conduct him/herself in a tznius way.
The same idea can be found in the way the Kohanim cloth themselves during their avoda in the Beis HaMikdash. Rabbi Falk quotes the Gemara in Zevachim 17b that says that when the Kohanim don't wear their special clothing, there is a lack of kedusha of kehunah. When they wear them, they have it in fullest.
The verse indicates that when their vestments are on them, their priesthood is upon them, but if their vestments are not on them, their priesthood is not upon them and their rites are disqualified.
See this edition of the sefer online.