Say I have $n$ boxes that are of unequal sides and unequally spaced. I want to arrange them in such a way that they are equally spaced.
My idea is to get the sum of spaces between them and divide by $n-1$.
How do I get the spaces between them using $(x,y)$ coordinates?

If you were putting the boxes in a line (i.e. if you were working in 1 dimension), then your method would work just fine, but with more dimensions, things immediately get a lot more tricky.
For example, what do you do when you have $13$ boxes? Make $2$ rows of $4$ and $1$ row of $5$? And even if you have a non-prime number like $20$, would you put them into a $4$ by $5$ layout ... or would a $2$ by $10$ pattern be just as acceptable? (and if the latter, why not go back to a $1$ by $20$?) ... or, since the sizes are all different, would you maybe end up placing $3$ big boxes in one row and $7$ smaller ones in another after all ... so that the fact whether the number is prime or not is in fact irrelevant? Will there even be any discernable rows or columns?
How, in fact, is 'equally spaced' defined? If it is the distance between the outsides of the boxes then you can't even do that in a two-dimensional space ... unless you end up lining them all up again. But maybe it's the distance between the center points of the boxes? (but still having the boxes not overlap). That would certainly make for an interesting problem, but noy one that has an easy solution or algorithm, as far as I can see.
Finally, do you have a fixed 'working area' to begin with? I get the impression this question is maybe about drawing rectangles on a computer screen, so do you have a given width and height to work with? Indeed, could you maybe provide a little more context for this question, so that maybe some reasonable options or 'acceptable' solutions could become more clear?