How does macOS select a name for a Time Machine backup?

The name of the Time Machine ’backup disk’ (‘WD MyPassport’ in your example) does not matter. You can rename this as you wish and Time Machine will continue to back up as usual. References to the backup disk name in places such as Time Machine preference pane will be updated accordingly automatically. Per tmutil man page:

In Mac OS X, HFS+ volumes have a persistent UUID that is assigned when the file system is created. Time Machine uses this identifier to make an association between a source volume and a snapshot volume.

The computer name (‘GregoryMBpro’) is used as the ‘machine directory’. Like the backup disk, you can rename your computer such as from the Sharing preference pane and Time Machine will continue to back up to the previous computer name. This is because…

Machine directories and sparsebundles are owned by one computer at a time, and are tracked by unique identifiers rather than computer name, host name, or ethernet address.

However, unlike renaming the backup disk, renaming your computer doesn't rename the actual directory path used for backups — rename your computer and it will continue to back up but to the old computer name.