I thought a lot about your question last night and to be honest I don't have a good answer or even know if there is one.
I've said it before but I personally felt that Milley and McKenzie should've resigned for the way the Afghan withdrawal was conducted. That isn't really an answer to your question though, because they just happened to be the guys in charge when everything came crashing down; tough to blame them for at least 18+ years of official fallacies we (both State and DoD) were telling ourselves and the American public about how the war in Afghanistan was going.
My thoughts in no particular order.
1. Part of this is cultural, both in our military and in our political leadership. We (in the officer ranks) all should bear some responsibility for this. On the military side, we rarely (almost never) want to or will actually say "no". It's in our DNA that if we're given a task or mission, we'll figure out a way to get it done. And nobody gets promoted for saying they can't accomplish something (see the Navy's destroyer mishaps as the latest example of severe consequences of this mentality). We've grown and groomed our leadership this way. Almost no one from the top generals/SESs down to probably the at least the FGO level wanted to admit that things weren't going well and that the goal of an independent, democratic Afghanistan free from most Taliban/VEO interference (if that was the goal) wasn't attainable (at least not in any reasonable timeframe).
2. We (talking the royal we, USA at large) tend to have a belief that the US is capable of accomplishing anything if we set our minds to it. And in the late 90s-early 2000s we were still coming off of the rapid, smashing success of Desert Storm. The American public was willing to keep things going so long as the casualties were relatively low and they didn't have to personally pay anything for it. Our public is also as separated from the military as it's ever been and our political class hasn't voted for "military action since the AUMF back in '01. A lot of us also mistakenly hold the belief that everyone in the world wants our version of democracy.
3. "Sometimes you have to let things fail". Don't know how many times I've heard senior leaders say this one in my career but I've rarely seen it actually utilized. I get that "failure" with something as large as the entire Afghan campaign is orders of magnitude different than some new process at the squadron level but it feeds back to point #1. Nobody in our senior leadership wanted to be the guys holding the bag when things ended in the Stan. They would have rather kept the war going indefinitely than admit our ever shifting goals were unattainable. Honesty was less acceptable than the static quo because no one could admit that we were going to fail.
4. Tactical success vs. Operational/Strategic failure. This one goes without saying. If our Operational/Strategic goals were unattainable from the get go, 20 years of killing people and spending money was never going to translate into a win.
To answer your original question about who to hold accountable, I honestly think it's probably the bulk of the DoD and State leadership chain for the last 18 years (from at least O-6s all the way to the top, maybe lower). I don't believe the US military was able to be honest with either itself or our civilian leadership about the war. I understand that's probably not a popular opinion. I know a lot of vets were having trouble (a lot probably still are) processing what happened two months ago. The bulk of the rhetoric/messaging has been aimed at us doing our duty, no more attacks on the homeland, etc. That's all well and good, and probably appropriate for the time, but we lost, and I think we need to figure out how to avoid these sort of mistakes/failures going forward.
I don't think anyone is going to get fired over this, so to your question over accountability, it'll probably be hashed out in the history books versus public hearings, resignations, some GO/FO or retired GO/FO actually saying "I'm responsible". Not a very satisfying answer I'm afraid.