The problem is the Applescript (osascript) call in your script. Applescript messages that call for user interaction don't work well when they are done via a root session, the way a Casper Suite policy will do. Its not Casper's fault. Its the OS doing its job of protecting the user space. Essentially osascript commands called by root can't display to the logged in user (unless the user logged in is root of course)
There are a few ways around it. You can try calling the command as the user with a sudo -u $loggedInUser type syntax, but sometimes even this doesn't work. The more reliable way would be to use launchctl asuser (10.10 & 10.11), orlaunchctl bsexec (10.9 and below)
Another way would be to ditch Applescript and use something like cocoaDialog, which doesn't run into the same restrictions. But this would mean deploying a custom tool to your Macs. You may not want to do that, and I'd understand. Though cocoaDialog, while old now, is still very useful in many regards.
For using launchctl, you can try something like this. Keep in mind this will only work on 10.10 and 10.11. The 'asuser' syntax doesn't exist in earlier OSes.
#!/bin/bash
loggedInUser=$(stat -f%Su /dev/console)
loggedInUID=$(id -u "$loggedInUser")
ComputerName=$(/bin/launchctl asuser "$loggedInUID" sudo -iu "$loggedInUser" "/usr/bin/osascript -e 'tell application "System Events" to set ComputerName to text returned of (display dialog "Please Input New Computer Name" default answer "" with icon 2)'")
echo "$ComputerName"
Just fill out the remainder of the script with the rest of what you wrote. The above should work, but I only wrote this right here and didn't test it, so give it a try.