This isn't actually the distance between two squares, but rather two points in a 2D space.

The distance between two squares should be computed (if they are not both axis-aligned) by finding which vertex is closer to the other square (so you'll end up with two most closer vertices, one for each square), and getting the distance between these close vertices.