Rendering Order in CustomDepth pass

I captured scene by RenderDoc, and found objects were not rendered as I thought.
Here is the situation: there are two cubes in the scene with opaque material, Cube0 is closer to the camera than Cube1.But Cube0 is rendered before Cube1 in CustomDepth pass. And I found Cube1 is not always rendered before Cube0 in the base pass,too.
This question confuses me because I was order to clear custom stencil on the Cube1 (with all bits,ignore depth) in the region where Cube0(with 0-custom stencil, default write mask) rendered. It should work well if Cube1 rendered before Cube0 which is closer to the camera.
Thanks for all replies!