QIANWEI, China—Schoolchildren in a bucolic region in western China famed for steam trains and jasmine flowers thought little of it when police interrupted classes and asked all the boys to spit into small plastic boxes.

They weren’t told why, according to the accounts of several children involved. From kindergartens through high schools, hundreds of male students were ordered to give enough saliva so that a filter paper inside each box turned from pink to white. The change indicated that the sample was sufficient for forensic...