Tokyo is a large city that has a reputation (amongst Japanese people) for being unfriendly. If you observe Tokyo people on a train — you will see where this reputation comes from. Tokyo commuters seem to maintain a personal bubble. Absorbed in their own world, they zone out with an electronic device or take a nap. They are committed to pretending they don't notice each others presence.
The Tokyo bubble is a coping skill for the Tokyo environment. Foreigners who live in Tokyo long enough develop the same pattern of behavior.
If you include Tokyo, Chiba, Yokohama and Saitama as part of the great Tokyo area the population is over 25 million. Many of its inhabitants weren't born in Tokyo. People come to Tokyo from all over Japan to work and live. Traditionally, Japanese people lived in small farming communities and fishing villages. Community ties were strong. In Tokyo, this is lost — replaced by friends and company ties.
Tokyo people commute on packed trains. They live and work in dense urban environments. They are surrounded by large crowds of people on a regular basis. In this environment it helps to maintain a personal bubble.