The first box has two white balls. The second box has two black balls. The third box has a white and a black ball.

Boxes are labeled but all labels are wrong!

You are allowed to open one box, pick one ball at random, see its color and put it back into the box, without seeing the color of the other ball.

How many such operations are necessary to correctly label the boxes?

Just One!

Because we know all labels are wrong.

So the BW box must be either BB or WW. Selecting one ball from BW will let you know which.

And the other two boxes can then be worked out logically.