The doors in public buildings open outward to allow a large number of people quick exit in case of danger, such as fire. If the doors opened inward, people might pile up at the exit as everyone pushed to get through at once instead of stepping back to allow space for the door to be opened.
The front doors of private homes mostly open inwards because they sometimes have to be removed from the hinges in to allow furniture to be moved in. If the hinges were on the outside, burglars could remove them easily. Since there are fewer people in a home, there’s no danger of a pileup at the door in case of fire.
Source: Why do dogs have wet noses? and Other Imponderables of Everyday Life by David Feldman and Kassie Schwan