There is a very large literature on such problems which involve finding configurations which maximize the minimum distance over all fixed sized point sets in some compact metric space.

For a large number of points $k$ and $S$ a hypercube, a good approximate answer can be given by referring to the sphere packing literature (see for instance Conway and Sloane's book *Sphere Packings, Lattices and Groups* and online databases such as Nebe and Sloane's Lattices page, or Scholl's Sphere Packing Database among other sources). Here one can construct roughly optimal $M$ by taking all lattice points in the hypercube from an appropriately scaled lattice. For low dimensions it is conjectured that the optimal sphere packing density is attained for a lattice packing (where each sphere has as radius half the distance from the closest vector to the origin in the lattice) which has been verified for dimensions $d=2,3,8,$ and $24$, but for dimensions even as small as $d=10$ there are non-lattice packings denser than any known lattice packings (for more information on this see Elkies' survey here from the AMS Notices, although more recent developments answer some of the questions posed there).

For general $k$, to give exact solutions (even in two-dimensions!) may be very difficult. A related problem is of finding best packings of circles of the same radius in a unit square (a simple observation, as by rescaling, to any maximal distance set $M$ with all distances appearing being at least $d<1$, all circles of radius $d$ centered at the $k$ points in $M$ must fit inside the square of length $1+2d$ and be non-overlapping). Several recent papers on this problem appear from M. Locatelli and P. Szabó and their co-authors (see here, here, section two in the first link gives a few equivalents of this problem, one of which is the problem posed in the question). Packomania is a great resource to check best known configurations for particular numbers of points.

For numerical solutions which aim to be exact, many calculations of the large configurations rely on use of stochastic optimization techniques (finally, these can be found in a list of references for the constructions which appear on the packomania webpage).