What I got in my Junk Drawer Memory® is that it derives from the notion that a sailor, back in the old days of the Rocks and Shoals, wnated nothing more than to get as far from the sea as possible, buy a farm and settle down. Hence the euphemism, 'he finally bought the farm.' But what with the history of these romantic sounding etymologies these days, I dunno. According to Dave Wilton the phrase 'buying it' predates the phrase 'buy the farm' by over a century:

http://www.wordorigins.org/wordorb.htm#buyfarm