A spectral version of Mantel's theorem