I've observed the Legend widget displaying the wrong symbology for some layers; in particular, the Legend will take the symbology for "layer b" and display it for "layer a". I'm fairly certain this is the same problem mentioned in this thread, which was observed in 4.16. Below is a description of the cause and a proposed 4.17 solution for those who need a fix "now".
The ActiveLayerInfo class has an internal dictionary for caching legend information retrieved from the server. Keys for this dictionary are generated for each service based upon whether or not the service supports dynamic layers. If dynamic layers are supported, the key is the long JSON string passed as the "dynamicLayers" parameter in the legend request. If dynamic layers are not supported, the key for the layer is the string "default".
This cache is shared across all instances of ActiveLayerInfo. The intent here is good, in that it can eliminate redundant requests to the server for information that the application has already retrieved. However, the key generation is highly susceptible to collisions.
For example, it is possible for multiple layers that do not support dynamic layers to share the same key "default". Since there is only one entry in the dictionary possible for this key, it will always store the most recently retrieved legend response. As a result, when layer symbology is rendered in the legend, a layer can incorrectly display the symbology for a completely different layer.
A fix for this is to generate better keys that have fewer collisions. If you're using a locally hosted copy of the API, you can do this yourself. In my solution, I've prepended the layer's URL to the key. In this case you will need to do two find-and-replace operations in the file esri/widgets/Legend.js. Note, this solution is for version 4.17, and may not work with other versions.
Part 1: search for (in function _getLegendLayers):
var b=(a=a&&a.hasDynamicLayers?a.dynamicLayers:null)||"default",e=I&&I[b];
Replace with:
var b=this.layer.url+((a=a&&a.hasDynamicLayers?a.dynamicLayers:null)||"default"),e=I&&I[b];
Part 2: search for (in function _generateLegendElementsForSublayers):
p=f.hasDynamicLayers&&f.dynamicLayers||"default"
Replace with:
p=this.layer.url+(f.hasDynamicLayers&&f.dynamicLayers||"default")
It should be further noted that my application uses multiple instances of the Legend widget simultaneously, but if I understand this problem correctly, it could still manifest itself when using a single Legend instance.