Do you mean as a species or as an individual?
As a species it seems we still don’t really know, on wikipedia (https://en.wikipedia.org/wiki/Bipedalism#Primates) they say that there are least 12 different hypotheses regarding how and why bipedalism evolved in humans, and even about when. It was probably driven by a combination of factors .
As an individual, humans take a while to learn how to walk (around 1 year) because we are born at a stage when our brain is still very immature compared to other animals (for example a foal can start walking straight after birth). Researchers think that this happens because we have very big brains and skulls and if we were born later, when our brains are more mature, our mothers wouldn’t be able to give birth to us – in parts because our pelvis has become smaller because we walk on two legs.