It's nominally to fund general facilities, etc. At least at public universities, it does wind up indirectly supporting departments that get less grant money or (more commonly) just general overhead/funds. However, it's not explicitly for that. It's just that universities take at least half of any grant you get. There's a reason large research programs are pushed for at both private and public universities. They do bring in a lot of cash that can go to a lot of things.
This also factors a lot into postdocs vs grad students. In addition to the ~50% that the university takes, you then need to pay your grad student's tuition out of the grant. At some universities, that will be the full, out-of-state/unsupported rate. At others, it will be the minimum in-state rate. Then you also pay a grad student's (meager) salary out of the grant. However, for a post-doc, you only pay their (less meager, but still not great) salary. So you get a lot more bang for your buck out of post-docs than grad students, for better or worse. This has led to ~10 years of post-doc positions being pretty typical post PhD in a lot of fields.
With all that said, I know it sounds "greedy", but universities really do provide a lot that it's reasonable to take large portions of grants for. ~50% has always seemed high to me, but I do feel that the institution and facilities really provide value. E.g. things like "oh, hey, my fancy instrument needs a chilled water supply and the university has that in-place", as well as less tangible things like "large concentration of unique skillsets". I'm not sure it justifies 50% grant overhead, but before folks get out their pitchforks, universities really do provide a lot of value for that percentage of grant money they're taking.