A gravitational field and a magnetic field both decrease in strength at the distance squared. They are two totally different forces so why the correlation?
The vanishing divergence without sources in the common reason for both inverse square laws, indeed.
To have a magnetic field decreasing as inverse square law, you would need (unobserved) magnetic monopoles, however. It is easier with electric fields.