EDIT:
New and (hopefully)Improved!:
As stated above, and as pointed out by Theo, a having both $A,B$ be closed but neither of them compact is not enough, a counterexample being that of S={(x,0)} and $S'=\{(x,1/x)\}$ in $\mathbb{R}^n$, as well as other counters given in the above comments. And the above assumption of $A,B$ both closed doesn't either allows us to conclude from $d(A,B)=0$, that there is an $a$ in $A$ with $d(a,B)=0$; for this last, we need to use the full hypothesis, i.e., we need $A$ to be compact. After showing that $A,B$ as given and $d(A,B)=0$ implies the existence of $a$ with $d(a,B)=0$, we use the fact that points at distance $0$ from a subset $S$ of a metric space are precisely the points in the closure of $S$, to lead to the contradiction that $A,B$ are not disjoint if we assume $d(A,B)=0$.
So we prove that $d(A,B)\neq0$ for $A$ compact, $B$ closed and $A,B$ disjoint.
Without compactness, the best we can conclude from $d(A,B)=0$, is that there are sequences $\{a_n\}$ in A and $\{b_n\}$ in B, with $d(a_n,b_n) \lt 1/n$. But now we use compactness+ metric, to use that there is a convergent subsequence $\{a_{n_k}\}$ of $a_n$; say the limit is a. Then, given any positive integer n, we can select an index j in $\{a_{n_k}\}$ with $d(a_{n_k},b_{n_m})\lt 1/2n $ for $m\gt j$, and, by convergence of ${a_{n_k}}$ to a, it follows that $d(b_{n_k},a)$, and so (triangle ineq) a is in B, (since B is assumed closed, and a closed subset of a metric space contains all points at distance 0 from B; specifically, in a metric space, the closure of a subset contains all points at distance 0 from that subset), contradicting the assumption that A,B are disjoint.
Note that the choice of $S:=\{(x,0)\}$ and $S':=\{(x,1/x) : x \in \mathbb{R}\}$ is not a counterexample, since the sequence $\{1/x\}$ does not have a convergent subsequence. Then S is not compact.