China's factory activity unexpectedly contracted in July, the first slump in five months, adding to signs of slowing economic momentum.