Ideally, I'd go to one of the top 4 departments: Stanford, MIT, Berkeley, CMU. Graduates of top universities with decent skills don't have a hard time finding jobs. I'll probably add Columbia and Harvard (middling departments, strong lay prestige) as (irony here) "safety schools". A quant fund isn't going to know the difference between a Harvard CS PhD and one from MIT (or might put Harvard higher).
Anything below the top 20 (and it's top 10 in the rest of STEM and top 1-2 in humanities) has to be purely for the education, though. You're right that a #40 PhD, while the educational program is probably fine, won't fix your career.
Also, the academic job market is terrible and that does not change if you have a PhD from an elite department. That's not what I'm aiming for.
What it can get you is opportunities that people without the PhD don't have available (like corporate research teams that only hire people with PhDs or put them into a separate class called "researchers" vs. other people who are hired strictly to write code).
Whether it helps you longer term in the positions that are available to non-PhD holders entirely depends on you. I've seen plenty of people with PhDs struggle to advance and plenty without PhDs excel while working in the same environment.
Anything below the top 20 (and it's top 10 in the rest of STEM and top 1-2 in humanities) has to be purely for the education, though. You're right that a #40 PhD, while the educational program is probably fine, won't fix your career.
Also, the academic job market is terrible and that does not change if you have a PhD from an elite department. That's not what I'm aiming for.