I have found a great explanation here, by itaiferber:
However, this seems like a very subtle difference when writing such a code, in that case wouldn't it be better to include AnyEncodable in the stdlib? I guess there are many others that implement AnyEncodable as value.encode(to: container) instead of value.encode(to: &container).