The $newTags object should clone $resource tags collection.
For example we have a resource with tags 'aaa' ,'bbb';
Then we want to change tags to 'bbb', 'ccc';
$newTags = $resource->getTags();
$tagsToAdd = $newTags;
Then we remove 'bbb' tag from $tagsToAdd ($tagsToAdd->removeElement($oldTag)), because we don't need to add this tag, it already exists. But oops, it is also removed from $resource and the $resource->getTags() collection is not actual.