The first category: those whom one is required to shun. This includes an innovator who calls others to his innovation, when he will desist only if he is shunned. In that case, we are obliged to shun him, because shunning serves a benefit: namely, that he ceases calling to the innovation. Thus, if we find someone calling people to the view that the Quran was created, or that Allah, Most High, is everywhere, we must shun him: we should not greet him, return his greeting, accept his invitation, or speak to him as a friend. For shunning him in this case serves a benefit. It is authentically established from the Prophet, peace and blessings be upon him, that he commanded the shunning of one who committed a prohibited act, as in the account of Ka'b and his two companions, may Allah be pleased with them (1). Yet one who commits a prohibited act is less serious than one who calls to an innovation, because an innovation persists through calling others to it, whereas the one who commits a prohibited act has committed it and that is the end of it.
The second category: those whose shunning is recommended. This is the shunning of one who commits a sin less serious than innovation, when there is benefit in shunning him—for example, shunning someone who shaves his beard. If we see a person who persists in doing so, and shunning him will serve a benefit—namely, his return to the fold of the sunnah—then shunning him is recommended until he returns. The same applies to one who smokes and to an employee working in usury-based institutions. We do not say that it is obligatory, because we cannot be certain that it will cause him to abandon the prohibited act. If we were certain that it would cause him to abandon it, then shunning would be obligatory.
Thus, in this case shunning is recommended, on condition that it serves a benefit. If there is no benefit in shunning him, then he should not be shunned, because the basic ruling is that shunning a believer is prohibited.