The Nazis, led by Adolf Hitler, hated the Jews; they believed that they were an inferior race of people responsible for all the world's problems. Once he came to power, Hitler systematically persecuted the Jews, banning them from numerous occupations, stripping them of their civil liberties, and licensing Nazi thugs to commit acts of violence against Jewish people, their properties, businesses, and places of worship.
When the Second World War got underway, the Nazis stepped up their persecution of the Jews, with many being forcibly sent to concentration camps, where millions perished. When the Germans invaded Holland, Jewish families like the Franks were in serious danger of suffering a similar fate to millions of others like them.
That's why they had to hide from the authorities in order to survive. The secret annex in which Anne, her family, and her friends, were forced to hide, was both a reality and a metaphor for how the Nazis treated the Jews. Cooped up inside the annex, no one has any real freedom to speak of. But then that reflects the hatred that the Nazis have for the Jews. As far as the Nazis are concerned, the Jews don't deserve freedom; in fact, they don't even deserve to live. The partial restrictions imposed upon Anne's freedom by life in the secret annex is a tragic foretaste of the absolute restrictions that will be ruthlessly imposed by the Nazis when they send her to the Bergen-Belsen death camp.