So, when you deploy, CodeDeploy will look for a file (on the instance) with information on previously deployed files for the application/deployment-group in question, if it finds the file it then it uses it to cleanup (delete) the existing files, preparing for copying of the new revision files.
Refer This AWS Documentation
But if the cleanup file doesn't exist, either because the existing code was initially deployed in some other way (eg cloudformation instance userdata/metadata sources) or the CodeDeploy deployment-group has been recreated for some reason then the cleanup file will either not exist or not match the deployment-group id. Therefore it wont be run. Therefore the files will not be cleaned up, and the deployment will fail since CodeDeploy does not overwrite files.
What a Solution could be in this scenario is to have a hook (eg BeforeInstall) that calls a script to delete the applications files (if they exist) on the instance.
Hope this helps