This thought experiment is most often called "The Twin Paradox."
The mistake lies in the fact that B actually changes his own frame of reference when he reverses direction, changing his velocity. There are not two but three separate frames of reference.
On the first half of B's journey, B would in fact see A's clock moving slower relative to his own. But if he were to "look" at his future self, he would see that his own clock is moving even slower than A's clock. Similarly, on the second half of his journey, if he "looked" at his past self, he would see it moving even slower than A's clock. At the end of the journey, A would be older than B.
Some people say that this paradox requires taking into account General Relativity, because acceleration is involved. However, perhaps twin B, rather than turning around, crossed the path of twin C, who is the same age, and going in the opposite direction. Even though there is no acceleration in this alternative situation, the results should be the same.