First off, let's start by noting that there is no clear moment in the text in which the purpose of the lottery is noted. However, we can speculate a few possible reasons why the lottery was set in place by the village ancestors.
It is likely that the lottery had to do with an ancient blood sacrifice for crops, as evidenced by Old Man Warner, who said, "Used to be a saying, lottery in June, corn be heavy soon."
There are other clues that the lottery might be tied to a blood sacrifice for crops. The setting, a rural village in the summer, is another clue. The changing of tradition at a time when urbanization was gaining foothold in America could be another clue. In history, there are many examples of blood sacrifices for crops, particularly in Latin American cultures.
Regardless of the original purpose of the lottery, the reason it is being done has long been forgotten by the villagers. The villagers are continuing the lottery simply for the sake of tradition, not for a particular purpose. The villagers now participate in the lottery to kill, not for the greater good. Near the end of the story, the narrator makes this particularly clear: "Although the villagers had forgotten the ritual and lost the original black box, they still remembered to use stone."