You can enable an application deployment to automatically uninstall when the assigned resource is no longer a member of the target collection by checking the "When a resource is no longer a member of the collection, uninstall the application" checkbox.
However, I can't seem to figure out to enable this using PowerShell with either new-cmapplicationdeployment or set-cmapplicationdeployment.
Does anyone know if that is possible?