There is some confusing code that remains from the pre-OP_MSG wire protocol implementation.
In CommandProtocolImpl a MongoNamespace instance is constructed from the provided database name and MongoNamespace#COMMAND_COLLECTION_NAME, whose value is "$cmd". The namespace is than passed to CommandMessage, and subsequently only the database part is used:
extraElements.add(new BsonElement("$db", new BsonString(new MongoNamespace(getCollectionName()).getDatabaseName())));
All this is unnecessary and is a remnant of the old pre-OP_MSG wire protocol, which requres a synthetic collection name for commands that don't actually operate on a collection, e.g. ping is executed on the namespace admin.$cmd. With the new wire protocol, the collection name, if necessary, is typically the value of the first field in the command, e.g. {{ find: <coll name> }}, and omitted for commands that don't operate on a collection.
To make the code more understandable, the namespace should just be replaced with the database name, and the synthetic collection name should be removed. Note that currently there is a very confusing method on RequestMessage, getCollectionName, but it doesn't return the collection name you might think it does. It's always <db name>.$cmd.