The most commonly accepted explanation for this idiom's origin is traced back to a way people in early Scotland had for dealing with unwanted guests. Apparently, if one had an uninvited guest, or one who had overstayed his welcome, at dinner you would serve him an inferior, unappetizing, and poorly cooked cut of meat (typically mutton) the "cold shoulder". This would subtly- or not- let this person know that his presence was not desired and his comforts were not going to be seen to with any degree of care.
There is also another possible- and more literal- origin of this phrase. In the 19th century, women working in kitchens used to be responsible for carrying in blocks of ice. While doing so, they would not stop to talk to anyone, since doing so would cause them to get a cold shoulder.
"Ye may mind that the Countess's dislike did na gang farther at first than just shewing o' the cauld shouther- at least it wasna seen fartha; but at the lang run it brak out into such downright violence that Miss Neville was even fain to seek refuge at Knockwinnock Castle with Sir Arthur's leddy, wha (God sain her) was then wi' the living."