Write to stencil buffer but not to custom depth

This is indeed possible, sort of! A translucent material will write to the stencil buffer even if part of it is discarded due to the depth test. In the material, if you set Blend Mode → Translucent, enable “Output Depth and Velocity” to enable the Pixel Depth Offset pin, then set Pixel Depth Offset to some large value, e.g. 10000000, the primitive will be behind everything else in Custom Depth, but it will still write its stencil value.