Sorry, but I can't see why your code isn't getting it all in one run, but as it isn't, here's another suggestion, although this one sort of works in a backwards method, by getting the ip from the dns hash, then searching for it in the iptracker hash, and if found, deletes it. Hopefully this will work to give you the results you're wanting, even if it's not in the same method that you were trying.
Code:
alias ippurge {
  var %a = 1, %b = $hget(dns,0).item
  while %a <= %b {
    var %ip = $hget(dns,%a).item, %ip.item = $hfind(iptracker,%ip,0,w).data
    if %ip.item {
      var %ip.data = $remtok($hget(iptracker,%ip.item),%ip,1,32)
      if %ip.data {        .hadd -m iptracker %ip.item %ip.data      }
      else {        .hdel iptracker %ip.item      }
    }
    inc %a
  }
}