Might want to look up Treaty of Versailles, besides limited size of the German Navy in personnel strength, it also stated very clearly how many ships German Navy could have, what type, and number of ships in each type, and size of those ships.....
Usually the modular construction came about due to those shipyards inland next to large river wanted to build larger size/tonnage ships than the river/canal can handle any longer. Thus the modular construction built method allows smaller sections to be built and put them on barges to ship them down river to another shipyard at seashore for the final assembly. And this became true during WW2 for a lot of nation's inland shipyards were needed to meet the demands of tonnage built.
Besides, Germany's submarines in WW2, a lot of them were modular construction built with sections at inland shipyards, then shipped down to main shipyards for assembly, all due to German war machine can't get enough production going, and not enough construction slipways at sea......
Only mostly Germany able to use modular construction method during WW2, since their overall higher engineering skills, much better engineering of parts standardization than everyone else, and they were the one developed this method and everyone else started to copy it. I mean, this requires a very high engineering skills and standards to produce parts and to have sections and parts from different shipyards to fit together seamlessly with a very small margin of error. The normal one shipyard build ships from start to finish just has to worry about the whole ship fit together, while part A and part B can have a larger margin of error in size and can have part C or D make bigger or smaller on the site to try to bring the error of margin down to acceptable level, and so on and so forth. And this is where parts standardization comes into play. With good engineering skills and good parts standardization that creates smaller margin of errors, you open up a new way of building things than before that allows quick parts exchange for one.
Don't remember if Germany were able to start doing the modular construction before WW2..... But even if they were, what about all those treaties?