A criterion for planarity of the square of a graph