Without a hostname setting, a container is named after its own short ID, something like faef50dfeef1. Recreate the container for an update and the hostname is different.
docker run --rm alpine hostname
docker run --rm --hostname media alpine hostname
The first prints a random looking ID, the second prints media. In Compose the same setting is hostname: media on the service.
Most apps never notice, but some do. Media servers and sync tools often show the hostname as the server name in their clients, so after every update a new device appears in the list. Some apps tie a license, a cluster membership or a backup set to the hostname, and then a recreated container looks like a different machine.
I’d set it for anything that has a name visible to other devices. It costs one line and removes a source of odd duplicates.
The hostname is only what the container calls itself. Other containers do not find it by that name; on a user defined network they use the container name or the Compose service name, or a --network-alias. So setting hostname: db does not make a database reachable as db unless the service is called that too. And it does not change what the container is called in docker ps; that is --name.
Further reading: docker container run, Compose file reference: hostname