In 1905 Japan had fought against the USSR, and there was still rivalry. The Communist USSR had developed the Comintern: a group dedicated to spreading Communism around the world
In November 1936 Germany and Japan signed the Anti-Comintern Pact, an agreement to work together against Communism, later joined by Mussolini
By 1936 Japan had invaded much of China. They were concerned about the USSR invading, and they thought allying with Germany would reduce the chance of this