We cannot know for sure what factors influence a country’s culture and etiquette. We have no way of changing factors experimentally and seeing how the culture and etiquette are affected. Instead, we have to speculate. I would speculate that the major factors that have affected Japan’s culture and etiquette are its ethnic homogeneity and its dense population.
There are two main factors about Japanese culture and etiquette that we need to explain. First, we need to explain why Japanese are so concerned with group harmony rather than individual wants and needs. Second, we need to explain why Japanese culture is so hierarchical and formal. I would argue that ethnic homogeneity and population density explain both of these things.
Because Japan’s population has typically been very ethnically homogeneous, there is a much greater feeling of solidarity among the people. This is much less true in places like the US where there are many different ethnic groups, or even in places like France or Spain, where there have historically been different regions with different cultures and dialects. A culture that is very homogeneous will, we can argue, place a greater importance on group harmony.
Because Japan’s population is so dense, it is important to have hierarchy and formality so as to preserve group harmony. When there are many people living very close together, it is important to reduce conflict. One way to reduce conflict is to have clear hierarchies so that everyone knows their place. Another way to reduce conflict is to ensure that people treat one another very formally and deferentially. This is (I would argue) also why Japanese culture emphasizes hiding personal feelings at most times.
Thus, we can speculate that Japanese culture and etiquette came about because of the country’s cultural homogeneity and because of its dense population.