You can easily do this using stencils, here is a bit more information about post process and stencils: Post Process Materials in Unreal Engine | Unreal Engine 5.1 Documentation
Scroll down until you find the topic CustomDepth Stencil to learn how you can do this. You can alternatively look at my Highlight Shader available on my website: Elias Wick | Highlight