The traditional explanation is that drug users can be blackmailed and security compromised by adversaries threatening to reveal federally prohibited behavior.
It seems antiquated.
Edit: as cannabis use is transitioning to decriminalized, testing specifically for that will become antiquated. Standing crimes of course will remain leverage for bad guys.