Geometric phases and criticality in spin systems