Berlin had the nice example of a few square kilometers of the Tempelhof airport field being available. Public demanded to make it a park instead of constructing housing.
Almost anything with a tree on it is impossible to build on, and even if there is a building permit for the housing, attaching it to public transports like the S-Bahn or Subway is next to impossible nowadays.
Building codes in Berlin are not much weirder than in the rest of Germany, but they also serve to make constructing housing harder. E.g. there is a strict limit to building height, which limits buildings to 5 storeys (iirc) even in high-demand high-density areas.
Money is especially tight for the state of Berlin, while they get subsidized with lots of money from the other states (Länderfinanzausgleich), they still cannot afford to construct much of the necessary housing or the associated infrastructure themselves. Private investment usually will go elsewhere because the political environment in Berlin is poor. If there is rent control in Berlin and no rent control in Hamburg, of course money will go to Hamburg first.
There is also no political will to fix the above.
What I think is a bigger problem is the countless vacant lots all over the city. Even centrally there are tons of them, e.g. with only a one story supermarket or parking lots (as mentioned above) or sometimes it’s just overgrown. I wonder what the deal are with those. My guess is that the city already sold them in more dire times and now owners just sit on them until the real estate prices makes the time ripe to build something there. Can’t find another explanation for it.