All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger.
It appears – Allaah Knows best – that the disease that permits one to use forbidden medicines when there is no lawful medicine is the disease one predominantly thinks that it will cause his death or that leads to an unbearable hardship. We found that the jurists of the Shaafi’ee School of jurisprudence discussed the question “If a child smelled wine and (being addicted to it) it is feared that he will be harmed if it is not given to him to drink, would it be permissible to give him a quantity that would repel the harm from him? They answered: “If it is feared that he will die or that a disease would lead to his death, then, in this case, it is permissible (to give it to him to drink). Some of them [the Shaafi’ee scholars] commented on this saying: “It is enough for such a disease to lead to hardship.”
However, since you found a lawful medicine that drives this OCD from you, then praise be to Allaah. On the other hand, if a person is affected by such a disease, he should endeavor to avoid the whispers of the devil. For example, if a person is in a situation like yours, and he wants to pray, and when he wants to prostrate the devil whispers to him that he is prostrating to other than Allaah, then he should not pay attention to that; rather, he should say to himself, “I am prostrating to Allaah only”, and so forth. Moreover, you should know that you are not allowed to abandon the prayer and the prostration due to these assumed imaginary whispers. For more benefit on curing OCD, please refer to Fatwa 90425.
Allaah Knows best.