A sad business. My first reaction was that you simply cannot trust a Muslim double agent. But in this case, it looks like someone must have leaked his role to the Taliban.
It’s possible, of course, that he developed a guilty conscience and “got religion.” I imagine tribal loyalties would have warred with religious loyalties.
Although the US is involved, much of what is going on in Afghanistan and Pakistan is Muslim against Muslim, so the lines would be far from clear for someone trying to do the right thing.
But I suspect, as several have already said, that someone leaked to the enemy, and he was betrayed before he was turned.
I vote for he was a plant/mole from day one, not turned. Taliban have been very good at faking stuff. Remember the “journalists” that assassinated Massoud just before we launched our attack against the Taliban.