The other answers focus on the combinatoric way of understanding what is going on. However, it can also be seen from a more statistical perspective.
From the information given in the question, there is no obvious correlation between any of the factors. In the absence of a correlation - that is, with all events being independent - the chance of winning is 25%, as each wizard has a 50% chance of their nominated hat being black, and there is no correlation between those two chances.
But in spite of appearances, it is actually possible to set up some correlations that alter the probability of winning. Let's start by defining a few events:
Let $A_n$ mean that wizard A's $n$th hat is black.
Let $B_n$ mean that wizard B's $n$th hat is black.
Let $a$ and $b$ mean that wizards A and B, respectively, chooses hat 1.
Now, as the hat colours are random, we have $P(A_n)=P(B_n)=\frac12$ for each $n$.
This is where the correlation comes in...
If Wizard A chooses hat 1 if and only if Wizard B's first hat is black, then $P(a|B_1) = 1$.
If the reverse is also true (B chooses based on A's first hat colour), then $P(b|A_1)=1$.
Now, there are four ways to win, each of which is mutually exclusive. There's:
- $C_1=a\cap A_1\cap b\cap B_1=(a\cap B_1)\cap(b\cap A_1)$
- $C_2=a\cap A_1\cap \bar b\cap B_2=(a\cap B_2)\cap(\bar b\cap A_1)$
- $C_3=\bar a\cap A_2\cap b\cap B_1=(\bar a\cap B_1)\cap(b\cap A_2)$
- $C_4=\bar a\cap A_2\cap \bar b\cap B_2=(\bar a\cap B_2)\cap(\bar b\cap A_2)$
As they are mutually exclusive, we can simply add the probabilities, and so we need only look at the probability of each case. Note that the pairs of bracketed terms on the right side of the equalities are independent of each other. And this is where the correlation becomes useful.
Case 1:
We have $P(a\cap B_1)=P(a|B_1)P(B_1)=1\cdot\frac12 = \frac12$,
and similarly, $P(b\cap A_1)=\frac12$.
So for case 1, the probability is $\frac12\cdot\frac12=\frac14$.
Case 2:
We have $P(\bar b\cap A_1) = P(\bar b|A_1)P(A_1)=0\cdot\frac12 = 0$,
and so, for case 2, the probability is zero - it cannot happen.
Case 3:
We have $P(\bar a\cap B_1) = P(\bar a|B_1)P(B_1)=0\cdot\frac12 = 0$,
and so, for case 3 as with case 2, the probability is zero - it cannot happen.
Case 4:
We have $P(\bar a\cap B_2)$ and $P(\bar b\cap A_2)$. However, neither of these are in any way correlated - wizard A doesn't look at wizard B's second hat when deciding which hat to choose, and vice versa. As such, $P(\bar a\cap B_2) = P(\bar a)P(B_2) = \frac12\cdot \frac12 = \frac14$, and similarly for the second pair.
Therefore, we conclude that
$P(Win) = P(C_1)+P(C_2)+P(C_3)+P(C_4) = \frac14 + \frac1{16} = \frac5{16}$
All of this happens because we introduced the correlations. If the wizards choose randomly, then obviously $P(a|A_1)=P(a)=\frac12$, and the chance of winning is just $\frac14$, as expected.
The really interesting part is that it only works if they both do it, but it doesn't matter which hat each one looks at, nor does it matter whether black means hat 1 or hat 2 for each of them.