Screenspace edge detection on separate layer

I have a landscape with buildings in my scene. I hope to render the scene normally, yet where the buildings have highlighted edges.
I use some screen space edge detection on the buildings only, therefore they are in a separate layer called “edges”. Then I have two cameras, rendered on top of each other. This unfortunately doesn’t achieve what I aim for - the edges are always drawn even when a building is occluded / hidden. And the depth interaction with sprites is even stranger, yet this might be another issue.
Would maybe “ZWrite On” in my shader help in any way? Currently it’s off, but writing into the depth buffer might solve this issue…

Many thanks in advance for your ideas!

I managed to solve the issue.
For future reference:
I show what I did here: