Playing the devil's advocate, if the US is willing to negotiate with both the Taliban and official Afghanistan government directly, why not Hamas and Israel?
(I am not trying to equate these groups; just compare the official vs force relationships)
Because they can't win in Afghanistan and are planning a retreat, whereas gaza is this way due to historical reasons, but mostly because they don't pose a real threat.
> As far as Gaza goes, Hamas rules Gaza but they're not the recognized government.
It's definitely more complicated by that, there is some evidence that people in the Gaza area have definitely supported Hamas, but of course they're rejected by the PNA (which rules over West Bank) and Israel.
I'm not sure who you would ask to make policy in such a situation.
Just Hamas because they rule that area by force? That sounds a lot like asking Israel for the same reason.
I don't think there's a good/ automatic answer for these situations.