You are passing the /csp and /kc parameters to the signing utility, which is a fatal syntax error when working with modern hardware tokens. The /csp flag stands for Cryptographic Service Provider and is strictly engineered for legacy Windows CryptoAPI architectures. Your YubiHSM uses a Key Storage Provider, which operates on the newer Cryptography Next Generation (CNG) framework. When you feed a modern KSP name into the legacy /csp parameter, Windows attempts to force a modern hardware interface through a legacy software wrapper, immediately resulting in the 0x80070005 access denial because the legacy subsystem cannot associate the advanced hardware key handle.
Because your earlier testing with the certificate utility confirmed that the provider and key container are already perfectly bound in the Windows Certificate Store, you must completely remove the /csp and /kc flags from your signing command. Your command should simply target the certificate directly using the machine store flag and the certificate thumbprint, such as signtool sign /sm /s MY /sha1 <YourCertificateThumbprint> /fd sha256 test.exe. By stripping away the explicit provider overrides, you allow the signing utility to read the native CNG metadata embedded in the certificate. Windows will then seamlessly and transparently proxy the cryptographic request to the YubiHSM without triggering the incompatible legacy API.
Once you execute the clean command, the native Windows CNG subsystem will automatically look up the YubiHSM network connector URL and the required authentication password. Because you are executing this in the local machine context, just ensure that these specific YubiHSM authentication parameters are properly populated in the system registry under HKEY_LOCAL_MACHINE\SOFTWARE\Yubico\YubiHSM\KSP rather than your current user profile. This guarantees the background cryptographic process can silently authenticate to your network hardware without generating a prompt or failing securely.