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.