While the defined custom pass is trying to mask objects to not be grayed out, HDRP/Lit shader's Forward pass is used. And the shader variant for the pass is stripped out in the build process because the render pipline asset sets Lit Shader Mode as Deferred Only. Therefore the editor has the shader variant whileas the built player doesn't.
It sounds a bit complicated, but that is how our shader stripper works. And I think CustomPassVolume and CustomPass APIs are for advanced level users, so IMHO it is supposed to be something which the target user should understand!
In order to solve this, obviously the best way is you can write your own shader because the custom pass has a specific purpose to draw the mask texture, and which is different from HDRP/Lit. But there are also other simple workarounds.
Set Lit Shader Mode to Both or
Call CustomPassUtils.DrawRenderers() with an explicit shader tag that isn't expected to be stripped out(ex. "DepthOnly")