As mentioned in the documentation page linked below "Stencil functionality for objects rendered in the deferred rendering path is somewhat limited, as during the G-buffer pass and lighting pass, Unity uses the stencil buffer for other purposes. During those two stages, the stencil state defined in the shader will be ignored...": https://docs.unity3d.com/es/2021.1/Manual/SL-Stencil.html
This leads to your `WriteMask 32` not being set properly during the G-Buffer (as visible in the FrameDebugger, it's overridden to the '207' value, which has bit 5 set to 0) and thus not writing the value you expect).