I think I finally found the answer. It is implied by the first comment of this bug description:
https://github.com/docker/compose/issues/3415#issue-153068282
When we recreate a container we start by renaming the old container by adding the container short id as a prefix. If the start or create fails, the container is left with that prefixed name.