Just in case anyone is still looking into this topic - I have read an official document (Nanite Virtualized Geometry in Unreal Engine | Unreal Engine 5.0 Documentation) mentioning that nanite doesn’t support custom depth or stencil. I am wondering at this point if nanite will support custom depth or stencil in the future.
Edit - I have found this ticket (Unreal Engine Issues and Bug Tracker (UE-149878)). I am not sure if it’s related, but it might be worth sharing here.