One explaination circulating on the internet is:
In the heyday of sailing ships, all war ships and many freighters carried iron cannons. Those cannon fired round iron cannon balls. It was necessary to keep a good supply near the cannon. But how to prevent them from rolling about the deck?
The best storage method devised was a square based pyramid with one ball on top, resting on four resting on nine which rested on sixteen. Thus, a supply of thirty cannon balls could be stacked in a small area right next to the cannon.
There was only one problem — how to prevent the bottom layer from sliding/rolling from under the others. The solution was a metal plate called a "Monkey" with sixteen round indentations. But, if this plate was made of iron, the iron balls would quickly rust to it. The solution to the rusting problem was to make "Brass Monkeys." Few landlubbers realize that brass contracts much more and much faster than iron when chilled.
Consequently, when the temperature dropped too far, the brass indentations would shrink so much that the iron cannon balls would come right off the monkey. Thus, it was quite literally, "Cold enough to freeze the balls off a brass monkey!" (And all this time, you thought that was a dirty expression, didn’t you?)
The most likely explaination is, however, according to the United States Navy Historical Center, that this is a legend of the sea without true historical justification. The Historical Center has researched this because of the large number of questions it gets and says the term "brass monkey" and a vulgar reference to the effect of cold on the monkey’s extremities, appears to have originated in the book "Before the Mast" by C.A. Abbey. In that book, Abbey actually wrote that it was so cold that it would "freeze the tail off a brass monkey." The Navy Historical Center says there is no evidence that the phrase had anything to do with ships or cannon balls. Ah, well.