First of all, please be careful about generalizations like this. Not all children in foster care fail in school. That said, children in foster care are more likely than others to have problems, including academic problems. There are two main reasons for this.
The first problem is that children who are in the foster care system obviously come from some sort of negative background. They have been abused or neglected, for example. This means that their problems are not caused by foster care but rather by the situations that forced them into foster care.
But foster care itself can be problematic as well. Children often get moved around from home to home, which is traumatic and destabilizing in itself. They often get placed in unsuitable situations since there are so many children in need and so few people willing to take care of them.
For these reasons, foster children are more likely to have problems in school.