Not a Lawyer, but this seems like work-for-hire.
https://en.wikipedia.org/wiki/Work_for_hire
I assume Germany has something like this (possibly a EU requirement). It would cover more than just ghostwritten books.
Most software is written in a similar manner. Microsoft didn't write windows, lots of ghostwriting programmers did.