Hi. You have half the answer already in your post. Since you can grab the ComputerName from the Mac in a script with:
scutil --get ComputerName
You can use that as a variable to set the HostName string to the same with a scutil --set command. For example:
#!/bin/sh
## This creates a variable string with the result of the Computer Name
CompName=$(scutil --get ComputerName)
## Now use that to set the HostName to match the ComputerName string
scutil --set HostName "$CompName"
Keep in mind the above is very simplistic. It does no error checking or making sure the ComputerName is even set to something valid (though I don't know if such a check would be needed), but it is the basic framework of how you would do this.
You could also simplify this further with a one-liner if needed:
scutil --set HostName "$(scutil --get ComputerName)"