Question: Why has one fulfilled his or her mitzvah of tearing if he or she tears one’s garment over the dead even if done on Shabbos but not if one tears a stolen garment?
A. The issue here is a mitzvah haba b’aveira, a mitzvah accomplished in a sin. It should be no different whether the sin is stealing or transgressing Shabbos.
B. If one was eating matza on the night of Pesach which fell out on Shabbos, while walking from the private domain into the public domain thus transgressing the prohibition of carrying on Shabbos, he would not fulfill the mitzva of eating matzah since it was a mitzvah done in a sin. (See Be’ur HaGra note 48 in Shulchan Aruch Yoreh Deah 340:29.)
Answer: The Taz and Shach (Yoreh Deah 340:28, 28: 16 in Taz and 42 in shach) say that the difference is that if the garment was stolen then the garment itself is in sin (It’s a stolen object, just like the matza was a carried object) whereas if you just transgressed Shabbos with the shirt then the action is the problem but the garment itself isn’t part of the problem therefore it is not a mitzvah done through a sin.