hostname returns another device's name
By default, your Mac will take the host name from the router when it received a DHCP reservation reply.

You can change this by not using DHCP or fixing the router or as a last resort over-writing the host name once you notice it's gone amok:

sudo scutil --set ComputerName whatever
sudo scutil --set LocalHostName whatever