Afghan forces thought the hospital was indeed occupied by Taliban, which under international law, anything sheltering terrorists can be attacked.
It's not that simple.
To identify customary international law, you need to look at the practice of the countries involved. This site sums up the relevant practices pertaining to the topic of targeting civilian objects:
You must be registered for see links
A common phrase you'll find there is [...unless the civilian facility is used for] 'military purpose/objective'.
What is a 'military objective' ?
" In so far as objects are concerned, military objectives are limited to those objects which by their nature, location, purpose or use make an effective contribution to military action and whose partial or total destruction, capture or neutralization, in the circumstances ruling at the time, offers a definite military advantage. "
You must be registered for see links
Did the bombing of this afghan hospital offer a 'definite military advantage' ?
"Many military manuals state that the presence of civilians within or near military objectives does not render such objectives immune from attack. This is the case, for example, of civilians working in a munitions factory. This practice indicates that such persons share the risk of attacks on that military objective but are not themselves combatants. This view is supported by official statements and reported practice. Such attacks are still subject to the principle of proportionality (see Rule 14) and the requirement to take precautions in attack (see Rules 15–21)."
Was this attack proportionate? Did the US take enough precautions?
Some say that "The historical record suggests that the US bombing of an Afghan hospital may not have been an accident. "
You must be registered for see links
You can't just always say 'oh it was collateral damage, we would never intentionally target a hospital.' It's suspicious the least.
Of course proving that this was a war crime, is another question. So, I'm not taking sides, but it's not exactly correct to say that 'under international law, anything sheltering terrorists can be attacked.' It depends on.
"...the UN high commissioner for human rights, called the attack "tragic, inexcusable, and possibly even criminal."
But should it be considered a "war crime"?
"We don't know yet," says Leonard Rubenstein, director of the Program on Human Rights, Health and Conflict at the Bloomberg School of Public Health and Johns Hopkins University. Under the Geneva Conventions, hospitals can't legally be deliberately targeted for a military attack. In cases where the enemy is using hospitals as cover, however, they can become legitimate military targets. Also, care must be taken to keep the attack proportional to the threat, and to avoid civilian casualties.
Rubenstein explains that the key is understanding whether the US military knew the building was a hospital when it launched the attack and, if so, whether steps were taken to warn civilians that the attack was coming and to minimize harm. He says an independent investigation is needed to determine what the United States knew and when.
Ultimately, the International Criminal Court would be the judicial body to hear a war crimes case against the United States, but it's "highly unlikely" that would happen, Rubenstein says. The ICC looks at patterns of violations, not single incidents. Additionally, the United States and NATO are already investigating the incident, so under the "rule of complementarity" the ICC becomes a venue of last resort. If the US and NATO investigations can be defended as reasonably thorough and objective, it would be hard to bring a case to the ICC. Finally, the United States would resist going in front of the ICC, a point admitted to reporters on Monday during a briefing by State Department spokesman Mark Toner.
But MSF notes that the "attack cannot be brushed aside as a mere mistake or an inevitable consequence of war." In a statement posted to its website Tuesday, MSF wrote, "Statements from the Afghanistan government have claimed that Taliban forces were using the hospital to fire on Coalition forces. These statements imply that Afghan and US forces working together decided to raze to the ground a fully functioning hospital, which amounts to an admission of a war crime."
Even if the Taliban had been using the hospital—a claim MSF denies—the Geneva Conventions still require the United States to attempt to minimize harm and alert civilians so that innocents can get out of harm's way. "If the Taliban were there, it doesn't mean that [the US and Afghan forces] have the right to kill all the patients," Rubenstein says. "They still have to take concrete steps to minimize harm."
Patrick Skinner, an analyst at the security consulting firm Soufan Group and a former CIA officer, agrees: "Just because it's not intentional doesn't mean it's not criminal."
You must be registered for see links
MSF says the hospital was struck repeatedly on Saturday, even though everyone in the area knew it was a working medical facility. "We had made clear the exact GPS coordinates of our health facilities in the Kunduz compound to coalition forces, to Afghan forces, to Taliban and to U.S. officials, both in Washington and Kabul and in both the civilian and military leadership," Cone told NPR on Sunday.
"The hospital was full of patients. That was widely known. We had close to 200 staff and patients that were at the hospital at the time of the attack. I want to reiterate that the main hospital building where medical personnel were caring for patients was repeatedly and very precisely hit during each aerial raid while the rest of the compound was left mostly untouched. So we see this as a targeted event."
John Sifton of Human Rights Watch says the U.S. needs to carry out a transparent investigation into what went wrong.
"For almost 15 years now, humanitarian groups have been giving information about the coordinates of protected sites like hospitals, orphanages, schools to the U.S. military," he says. "The U.S. military asks for this information so that they can avoid these instances. When something like this happens, it suggests a major failure in their own systemic efforts to avoid civilian casualties."
Theoretically, there are cases in which hospitals could become legitimate military targets if combatants are misusing the facility. But even then, Sifton says, the military response has to be proportionate.
"You can't kill 22 people, including lifesaving medical staff, in one of the only medical treatment centers in the region, just to get a couple Taliban," he says. "Or even 10."
Still, it is a high bar to call the Kunduz attack a war crime, says Robert Goldman, who teaches international law at American University."
You must be registered for see links
So, of course, you can't prove it was intended...and well, even if one concludes that it was disproportionate and not all cautions were made, still nothing will happen.
Sorry for the long post, I just felt like elaborating
