You can check the device's hostname with net.hostname property (no root needed supposedly) but for setting it to take effect, needs rooting.
My question is, in what cases would result in blank net.hostname?
I noticed that on (GSM) AT&T Moto E (2nd Gen), net.hostname has a value. But on (CDMA) Sprint Moto E (2nd Gen), net.hostname value is blank when I fetch it via ADB. Both run Android 5.1, and both have their SIM cards removed, and the Sprint phones are not unlocked nor activated but the AT&T ones are. Not sure if those make any difference.
I would assume all Android devices should have a net.hostname. Unless for those with that property blank, the device pulls/uses hostname from somewhere else. I just checked on the router/access point side, and found the hostnames for these devices with blank net.hostname. Just wonder where to fetch hostname on the device side then via ADB, etc. for these problem devices.