Both expresssions are idiomatic, meaning much the same thing. If you say "He is a man in a black hat or he is a man with a black hat," either would be acceptable English. "A man with a black hat," in a different context could mean that the man has his hat in hand and is not wearing it. Eg., "Do you see those two men who are not wearing hats. He is the man with the black hat." The sentence is vague but would be acceptable in describing which man you have identified.
I would add that "man in a black hat" might be a figurative way of describing a villain or an antagonist; this metaphor comes to us from old cowboy movies ("spaghetti westerns"), where the "good guy" invariably wore a white cowboy hat and the "bad guy" wore a black one.
Whether "in a black hat" is meant literally, figuratively, or both in the text you are reading is not something I can answer.
That is a good observation. and the white hat/black hat goes back further than the spaghetti westerns. It explains why all of the kids from those 1930s wanted to be Hopalong when the movie was over with.