Quite simply, shunning is a control mechanism. It can be effective in any situation where the network of people you associated with is limited to a certain group, like in a cult. If you break the rules of the cult, you are thrown out, and you are cut off the the network of people you knew. No association at all. The idea is that you will be devestated by the loss of your associates and do whatever is necessary to re-join the group (cult).
JWs call it disfellowshipping and say it is to bring a person back to the true religion, but it is nothing more than a desperate attempt to control you.
Now, you do not have to be disfellowshipped to be shunned by the JWs. If you haven't done anything to be disfellowshipped, you can still be "marked" as bad association, and other JWs are advised not to associate with you. This is a kind of informal shunning. There is no announcement that you are marked, there may be a special needs talk that indicates you are not a good associate by pointing to things you have done as wrong, without actually naming you. Or more frequently the word that you are "marked" spreads by word of mouth through the rumor mill that is the JW congregation.