Tom didn't know because Bob and Bill were NOT both wearing white hats. If they were, Tom would know that he was wearing a black hat because there are only two white hats. Since Tom didn't know, that means to Bob and Bill:
1) both wear black hats
2) Bob wears a white hat and Bill wears a black hat
3) Bob wears a black hat and Bill wears a white hat.
But Bob also doesn't know what color hat he's wearing, but if Bill was wearing a white hat, he would know he was wearing a black hat, or if Bill was wearing a black hat, Bob would be wearing a white hat.
So Bill knows he's wearing a black hat!