Schools almost always admit legacies as a reward for, or in expectation of donations. Families that benefit from legacy admissions often feel grateful to the institution, and consequently donate money. Legacies are usually well-off, and they can afford donations to these schools. Of course, schools have something to gain from admitting legacies over more qualified applicants, namely, money.
It has only become common in the last few decades for most high school students to go on to college. In the previous generation, it was much more likely that if someone was economically disadvantaged that they could not afford to go to college at all. Therefore, legacy admissions necessary favor those families who have had money for some time.