SHANGHAI—China’s financial capital recently joined the global cadre of cities that have bewildering trash-sorting rules. Unlike the others, it is making sure the regulations have the full force of law.

Residents face spot inspections of their refuse from 30,000 trash-can enforcers as they throw out nightly waste. Authorities can levy serious punishments, prompting some people to try crafty workarounds.

Strategies...