You mixed up some units here: Brooklyn is way denser than SF (about twice as dense). Your SF number is people per square mile, not per square km.
Same units, Brooklyn is ~35,300/m^2, SF ~18,500/m^2
Manhattan ~69,400/m^2
all from https://en.wikipedia.org/wiki/List_of_United_States_cities_b...