As MSF's General Director, Christopher Stokes, said on Sunday, the latest official US statements "[amount] to admission of a war crime." They basically work out to "we heard there may be some Taliban soldiers inside the hospital, so we killed everyone in sight."
What seems to be the case, and what most sources have started to concede, is that the Afghan government has long hated the existence of this particular hospital, as (like all MSF hospitals) it has been known to treat whoever was sick or injured and came through the door, no matter which side they were on. It appears that the Afghans decided to call in an airstrike on it, and for reasons not yet clear, the Americans decided to do so and thoroughly bomb it, despite having fairly precise situational awareness and knowing what they were bombing.
The best estimates of the reasoning I've seen so far have to do with various negotiations between Obama and the Afghan government about the pullout of the last remaining US forces, and our government trying to make nice with them before we leave, to reduce the chances that they'll end up making an alliance with the Taliban. But bombing an active hospital to the ground seems like one hell of a way to make peace with, well, the sorts of people who think bombing hospitals to the ground is just peachy keen.
The article linked provides an excellent timeline, as well as quotes from all sides as the story unrolled, so that you can see how the official statements have shifted as each line became untenable in turn.
 Disclosure: You'll find me on their major donors list for the past decade.