echo 'Unattended-Upgrade::Remove-Unused-Dependencies "true";' >> /etc/apt/apt.conf.d/52unattended-upgrades-local
The default configuration file is
/etc/apt/apt.conf.d/50unattended-upgrades
You could name the new one as /etc/apt/apt.conf.d/52unattended-upgrades-local
See here for reference.
Option for All Ubuntu Releases
The following setting configures unattended-upgrade to remove unused dependencies after an unattended upgrade.
Make sure the configuration file contains line
Unattended-Upgrade::Remove-Unused-Dependencies "true";
(and that it is not commented out; comments start with '//'.)
Thereafter unattended-upgrades will automatically remove packages providing old kernels as part of unattended upgrade. (It does not purge them, however.) It also removes other unneeded packages, as well, which is or is not what you want.
https://help.ubuntu.com/community/RemoveOldKernels