A Mac has more than one name, and they do not have to match. That explains odd hostnames in SSH and on the network.
scutil --get ComputerName
scutil --get LocalHostName
scutil --get HostName
ComputerName is the friendly name from Settings, LocalHostName is the Bonjour name you reach as name.local, and HostName is the one the shell and DNS tools may use. HostName is often unset, and the command then exits with an error.
Set one with sudo scutil --set LocalHostName mac-studio. Local names may only contain letters, digits and hyphens.
Further reading: scutil manual page