Is it necessary to eject external drives before logging out, restarting, or shutting down?
No, it's only recommended when unplugging the cable.

The reason why you eject is so that any processes reading and writing from the disk will cause OS X to notify you of the disk being in use and prevent data corruption that can occur by just unplugging the disk while it's in use.

Additionally the OS might queue different write operations to a cache before actually writing them to disk, and ejecting will make sure these are flushed to the drive before it is disconnected.

Halting any processes from reading/writing to the disk and flushing the caches is implied when rebooting or shutting down the machine (unless you do a cold shutdown by pressing and holding the power button to turn it off). When logging out, the OS can flush the cache at its own discretion.