Black yarn was used in a number of German cameras to seal the top deck to the body.
I have a German camera from the early 1970s that uses black yarn. The older Contax I (and maybe the Contax II) also used black yarn.
I can't recall ever seeing foam used in an older German camera (mostly because the cameras pre-dated the invention of foam rubber). I've never had problems with light leaking into the back.
On most of my cameras, the backs have very deep channels or rails. Most of the modern-day camera backs have side rails that aren't too high, so possibly the foam helps to ensure a tight fit.
I've used black yarn in several cameras. Works fine, though you need a way to get it to adhere properly in the channel. And then you have to leave the camera back open until the adhesive is set. Otherwise, you run the risk of gluing the back to the body (you can probably guess how I know that).