The first step in the synthesis of ranitidine is a Mannich reaction on a furan compound (furfuryl alcohol) to produce essentially one half of the molecule. The key reagent in that step is dimethylamine hydrochloride.
The final steps of the synthesis involve conditions that will form nitrosamines from amines.
Thus, if any dimethylamine hydrochloride is left over after the first step, conditions exist to turn it into NDMA.
Dimethylamine is a bugger to get out of a reaction mixture, and it would not surprise me to find that a poorly-designed or badly executed reaction scheme may fail to remove some trace amounts, therefore opening the door to producing NDMA. In other words, as an impurity existing from the first step of the synthesis.
So it's not just a case of "NDMA accumulation".
I have had experience witnessing syntheses of pharmaceutical APIs at Indian manufacturing plants, and have seen some horror stories.
The NYT reports that Sanofi's recall "applied only to the United States and Canada, and that its products sold outside the two countries were sourced from different suppliers", which is fairly common practice. So it may be that only some API makers have the problem, which is likely a manufacturing and QC problem.