Looking it up, it was never banned, it was just prevented from being reprinted due to the government holding the copyright and not making it available. It’s now in public domain.
The German state of Bavaria has held the copyright for Adolf Hitler’s autobiography since 1945 and has withheld publishing the book, preventing any reprints in Germany. But in 2016, the book becomes available in the public domain, which will make it widely available in Germany for the first time since World War II.
That means it was perfectly legal to have it, it just couldn’t be printed in Germany.
Looking it up, it was never banned, it was just prevented from being reprinted due to the government holding the copyright and not making it available. It’s now in public domain.
https://www.pbs.org/newshour/arts/hitlers-mein-kampf-to-go-on-sale-in-germany
That means it was perfectly legal to have it, it just couldn’t be printed in Germany.