Mohammed,
I can not actually say exactly what you need to do as I dont personally use the API's Legend component, but I would guess that you need to set the Legends map to null and back again to the map component after a layer is hidden or shown from the layerTOC. In the layerTOC look at the hideLayer and showLayer functions.