There's a long standing "bug" in udisks which causes this to happen. It's actually "normal" behaviour for udisks - optical drives are a bit of an edge case where, though the media is removed, the drive is still present. This was been reported in the ubuntu bugtracker some time ago and a workaround using udev was suggested:
https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1168742
You already have a script which will unmount the drive - to get this to run when the disc is ejected add the following to a udev rule, e.g. /etc/udev/rules.d/70-unmount-cd.rules
KERNEL=="sr0", ACTION=="change", RUN+="/path/to/your/unmount/script.sh"
There's a load of good info in the above link, so check that out too.
HTH!