A frum person has OCD, and part of that affects them so that they bite or pick their fingernails a lot. This person might also bite or pick fingernails on shabbat, presumably related to OCD. Have they transgressed? If so, have they transgressed to the same degree that a non-OCD frum person would have transgressed by doing this on Shabbat? Is there a lesser degree of transgression for the OCD person, since their nail-picking is related to OCD?
If the person does it during the week, he is also going to do it on Shabbos. In fact, it is said from the Chazon Ish that a person who bites his nails is most probably mechalel Shabbos (at least on a d’rabonon level because he will inadvertently do it on Shabbos). Therefore, it would be considered a transgression. Regarding the level of the transgression, the way it works in the heavenly court is that the severity of the transgression depends on the difficulty it was to abstain from doing the Aveiro. If it was very hard to abstain from doing the action, although it is still an Aveiro, the punishment for it will be less than for a person who could have abstained from the Aveiro with ease. Nevertheless, we still must take concrete action, to help him abstain from biting his nails on Shabbos. The first thing is that he should go for help. Aside from that, it might help if he wears gloves, (during the times that he is apt to bite his nails) or put Band-Aids on the tips of the fingers that he might come to bite. Alternatively, it might help this person to get something to play with, such as a fidget ball, or something else to keep his fingers occupied. The person himself should think of options, whatever it takes to help him not to do this on Shabbos.
חזו”א (דינים והנהגות פרק י”ג אות ל”א) – “שמענו שראה אחד שכסס צפרניו בשיניו בחול, ואמר לו ‘אתה מחלל שבת’ (כלומר שמתוך ההרגל יש לחוש שיעשה כן בשבת)”. וע’ ג”כ בנשמת שבת (סי’ ש”מ אות ד’) – “שהנוטל צפרניו … כשנושכו בפיו … ואף שיתכן שעושהו שלא מדעת אלא מחמת הרגל (שנתהפך לטבע שני) ולא הוי מלאכת מחשבת, אכתי נשאר איסור דרבנן בדבר, ומחוייב למחות”