Transparency of whole image at the position of an object
Holdout based on a material

The Holdout shader node sets the alpha to zero for the area occupied by the object in the rendered image. This is documented in Blender's manual:


  The Holdout shader node is used to create a “hole” in the image with zero alpha transparency, which is useful for compositing (see alpha channel).
  
  Note that the holdout shader can only create alpha when Properties ‣ Render ‣ Film ‣ Transparent is enabled. If it is disabled, the holdout shader will be black.






Holdout for a collection in the current view layer

As Jachym Michal noted, you can also use the holdout restriction toggle to mask all objects inside a collection for the current view layer. It will not affect the visibility of the same collection in a different view layer.


Display the holdout restriction toggle:

Activate the holdout for, e.g. Collection 2:



This approach sets the holdout attribute for the LayerCollection in the current view layer.

Alternatively you can also set/clear the holdout from the context menu in the outliner, if you're using Cycles as render engine. This can be accomplished by right-clicking on the collection to open the context menu and then using either View Layer > Set Holdout or View Layer > Clear Holdout. At the time of writing this option is unavailable when using any other render engine, due to a hard coded check in OUTLINER_MT_collection_view_layer (space_outliner.py).