As already pointed it out, there is no scientific consensus on the answer to this question. This is because it is hard to test proposed explanations and it's likely that several factors interacted.
All of these have been claimed to be the explanation for the evolution of bipedalism:
1. Freed hands for increased tool use. (Encyclopedia Britannica)
2. Freed hands for the use of weapons in hunting or the use of containers to transport plant foods obtained by gathering. There are three variants: the “man the hunter” version which sees male hunting as the key stimulus (Washburn 1967 in Haraway 2013); the “woman the gatherer” version which sees women needing their hands free to carry gathered vegetable foods as the stimulus; and the “man the provisioner” version, which stresses males carrying food (either meat or plants) to provision females and offspring. All of these explanations are probably flawed because they invoke present utility to explain the origins of bipedalism.
3. Bipedalism was created by female sexual selection of males with large, visible genitals. Although unlikely, this may be correct, but it is impossible to test. (Encyclopedia Britannica)
4. Bipedalism evolved to aid in avoiding predators. Higher head allows you to see longer distances over the grass. (Encyclopedia Britannica)
5. Bipedalism evolves because it allows energy efficient locomotion between forest patches in an increasingly open environment.
6. 249
“Radiator theory”: Natural selection favored bipedalism in open environments because it decreases exposure to the sun and helps keep the brain cool. (<PERSON>, discussed in Haviland 2007 and Encyclopedia Britannica) Brain is highly sensitive to heat stress. This allowed hominins to be active in mid-day, when competing predators are less active. (Essentials of Physical Anthropology, p. 165). Since the same carnivorous animals with which hominins were in competition (both would scavenge dead game) could attack hominins, hominins were probably safer from predator attacks during midday as well.
7. Terrestrial bipedalism may be a continuation of an upright body posture inherent in a tree-climbing/brachiating adaptation. Gibbons, the most arboreal of the apes and the best brachiators, walk bipedally on the rare occasions they come to the ground. (Encyclopedia Britannica)
The earliest hominin fossils appear to have been bipedal, with no clear evidence of a transition through a knuckle-walking stage, the principal mode of locomotion of modern African ape. (<PERSON> and <PERSON> 2009, here's a secondary source, and here's a primary source that disagrees, <PERSON> and <PERSON> 2000)
If this is true, then the modern African ape mode of locomotion (knuckle-walking) is a derived trait, and vertical body posture may be the ancestral trait in the African hominoid evolutionary lineages. In other words, if this is true, the ancestor of all great apes including humans was already bipedal, and modern African apes have evolved to knuckle-walk since then. Also if this is true, the previously mentioned factors would reinforce and refine bipedal locomotion in the hominin lineage.
It is likely that explanations 4, 5, 6 and 7 all interacted to select for bipedalism. They correspond best to the paleontological and ecological data. Numbers 1 and 2 are unlikely, because bipedalism appears long before evidence of tool use. 249