Its the way that we have evolved, plain and simple. Humans evolved walking on two legs from a very special ape which roamed Africa around 3 million years ago, Australopithecus, one of the first apes to walk upright. Exactly when and why these apes did this is still a bit of a mystery but what is certain is how it opened up new opportunities for our ancestors. The ancestral humans who were best at standing would have been more likely to survive and pass on their genes, so it is easy to imagine how natural selection could have resulted in a gradual shift from simply standing up briefly to permanently moving around in an upright posture.
Looking away from early humans and to why dogs and most mammals walk on four legs is the length of their bodies and the position of their limbs. Most mammals bodies are too long for two legs and the evolution of dogs and most mammals are adapted to move faster on four legs and catch their prey or run away!