If we want to classify something as either a cat/dog or neither, do we need 2 or 3 classes?
If you want to determine if something is either a

cat/dog or neither

you need 2 classes:

one for dog or cat, and
one for anything else.

However, if you assign all cats and dogs to the same class $A$, if an input is classified as $A$, then you won't be able to know whether it is a dog or a cat, you will just know that it is either a dog or a cat.
In case you wanted to distinguish between cats and dogs too (apart from neither of them), then you'll need $3$ classes.
Finally, if you specify only 2 classes:

dog, and
cat,

then your CNN will try to classify any new input as either a dog or a cat, even though it is neither a dog nor a cat (e.g. maybe it is a horse).