I'm nowhere near an expert on this and am largely retelling what I've learned from an expat. As I understand it, after WW2 the US released thought criminals from prisons and jailed the war criminals, but then this led to a resurgence in leftist thought which had the US freaking out and Reverse Course aka the Reverse Occupation.
Pre-WW2, might wanna read about the Rice Riots of 1918. Also, the Tiasho era 1912 to 1926 had a weak emperor so there wasn't a lot of top down repression which allowed for a lot of grassroots organizing.
Here's a Jacobin article on The Heroic Origins of Japanese Socialism