Japanese importation of select aspects of German culture has a fairly long history; I phrase it this way as the ways in which Japan has imported products and aspects of German culture has very often been a conscious and limited act initiated by Japanese interests. This is notably different from how British culture spread during the apex of empire and also distinct from the adoption of American popular culture in modern times.
Rather than spread by force of arms, by power of commerce, or by global cultural movements many of these items of German culture were imported and popularized due to the initiative and decisions of individuals or small circles within Japanese society; these products of culture were often small and specific rather than parts of broad movements. So while the popularization and pervasiveness of any individual import was often the product of more organic processes within Japanese society, they stand out within Japanese culture because of the mail-order catalog nature in how they were brought there. This was not unique to the Japanese-German cultural relationship either but defined how many small pieces of foreign culture and custom were imported and adapted to suit Japanese needs; this was done so successfully that some of these imports have since become more closely associated with Japan than the places they originated.
Consider Japanese school uniforms; while the iconic Japanese school-girl outfit may become something many associate first and foremost with Japan it was actually an imported style patterned specifically after British sailor outfits. The commonly depicted boy's school uniform is also a similar sort of import - patterned specifically after Prussian army uniforms. Other less recognized Germanic (though not strictly of modern Germany) include stylization of certain aspects of military dress, fashion and the model for the education system. These earlier German/Prussian imports may be related to the industrialization efforts that partly defined the Meiji Restoration and that these coincided with the Prussian/German unification and rise to prominence of what would become modern Germany. If you're going to consciously look outward for models on which to industrialize and unify your once fractious and feudal country, I imagine a nation whose cultural trajectory and modernization modeled that which you sought for your own might seem a good place to look shop for ideas. It is easy to forget that some of these things - such as some styles of dress and the Prussian education model for example - are specifically Prussian early post-unification Germany imports because they were also adopted by the US, Austria and Napoleonic France around the same time and so may seem non-specific European/Western.
Leading up to World War II we can see similar parallels that might have made Germany seem an eminantly relevent and appealing source of ideas for Japan to import. While Japan came out of World War I having risen to global prominance and having fought against Germany, their situations became far more similar than the end of that first war might have lead one to predict.
They came out of the war very differently but this changed rapidly as Japan's economy entered a long recession. Soon enough they could both be said to be debtor nations, their people suffered large-scale economic downturns possibly made worse by the imposition of trade barriers by many western powers aside from those which would later form the Axis. By the 1930s Japan was also limited by strict naval and arms treaties which may have made those with nationalist sentiments see a commonality in the obstacles faced by themselves and Germany. The perception of being stifled and stymied by American and British interests served to spread civil disorder, anti-foreign sentiment, and ultra-nationalist fervor during this time - something else that might sound familiar when looking at 1920's and 1930's Germany. This wasn't some blind love of all things German - Japan developed its naval training, structure, and technology by considering Britain. Even after hostilities broke out they continued to seek technology and insight on naval air power from Britain - though by then this had to be solicited from men such as Lord Sempill rather than through official channels.
Now consider the economic turn-around, defiance of post-war restrictions, and appeal of nationalist and nazi rhetoric in Germany at that time. Japanese ultra-nationalists with an eye on Empire would have surely seen aspects of that as a useful basis for establishing themselves in an increasingly dissatisfied and disordered Japanese society (terrorism, coup attempts, and riots did occur during this time which could be compared to the events which helped pave the way for fascism in Germany.) So at this time there - even before formalized alliances or even the solidification of Nazi rule - Germany served as a source of inspiration for ambitious radical ultra-nationalist politicians on the other side of the world. During the war, particularly when Hitler's Germany was burning across Europe, I imagine this impetus to import and make-Japanese things they saw in Germany that they thought useful persisted and even grew stronger.
Now I suppose the real question might by - why is there not an aversion to things that might remind us of Nazi Germany in particular as there is in many western nations? In popular literature and animation in Japan there are examples of fictional countries whose resemblance to fascist Germany and the relatively neutral portrayal of the setting itself could not avoid stern admonishment in countries such as England or the United States. That might be related to how some of those concepts - corperate statism, imperialist nationalism, and the far more incidental but readily visible aspects of styles - were imported. German litterature popularization and limited culural exchanges during this time might go towards explaining the varying degrees of German-inspired settings which persist in some Japanese fiction to this day.
That is, they didn't come over in a broad wave of nazi-style fascism as they did in say Spain. Those things that remind us of Nazi germany - to some extent - were imported individually, adapted and made Japanese, and became part of their cultural fabric rather than being seen as intrinsically linked to what they may have come from. Consider perhaps some aspects of the culture and custom in the south of the United States; I eat and enjoy southern BBQ and low-country cuisine without the origin of much of that food being deeply tied to the institution of slavery. Some aspects of Imperial Japan and earlier modern Japanese culture that persist to this day are seen similarly even in cases where many Westerners might have a loudly-conscious association with Nazi Germany upon seeing them. Of course I mention the post confederate South in part because I do think it is important not to divorce pieces of cultural identity entirely from their origins. There are offspring of rightly-dead things that themselves would be right to die such as racial discrimination and outright race-based hatred.