The points of a square can only be one of two lengths. A side or a diagonal. Just given any set of 4 points we don't know which pair are diagonally opposite or which are adjacent
Without loss of generality you only need to check 4 distances:
║A,B║;
║A,C║;
║A,D║;
And one other ║B,C║; ║C,D║; or ║C,D║.
As what @Floris said, using square distances is easiest.
Of the three distances two will be equal (this distance will be the side length (squared)), the third must be a diagonal and thus 2 * side^2.
To pick the last pair, you need to pick the point which is diagonally opposite p1 and one of the other two points (B or C). This distance must be equal to the side length.
This does not, as @Kos pointed out, solve for the situation of a bow-tie shape. Yet if this is a consideration then the ordering of the vertices matters, then you can treat the input as a list of ordered points, and then you can setup the function arguments so that A and C are diagonally opposite, and so are B and D.