US slang, from the WWII era (first printed record in the US Air Force in the 1950's). Similar expressions like buy the plot and buy the lot also existed, although buy the farm is the only one to have survived. Probably related to older British slang buy it, buy one or buy the packet, both seemingly ironic references to something that one does not want to buy. May come from the common reflection that servicemen would often dream of saving up to go home and buying a farm to settle on after the war or their deployment is up, but the deceased receive a small plot of land (the grave) automatically. Alternatively, folk etymology holds that the insurance payout to the soldier's beneficiaries and/or the military pension provided to the bereaved dependents may have, ironically, fulfilled his old dream, and allowed his surviving family to pay off all loans on the family farm, or let them purchase one. This, however, can only explain farm; meanwhile, plot and lot are clearly bitter sarcasm about finally ending up with a piece of land all one's own - the grave spot allotted to the deceased.