Change active View Layer with Python
Set Window.view_layer

From https://code.blender.org/2017/09/view-layers-and-collections/ 


  For simplicity now, we stick to having a single ‘active View Layer’
  per Blender window.


Set the view_layer property of the context window to the view layer you wish to be active for that window.

Example using py console. I have 3 viewlayers "RenderLayer", "View Layer" and "XXXX", code below sets "XXXX" as active in current (context) window.

&gt;&gt;&gt; vl = C.scene.view_layers['
                              RenderLayer']
                              View Layer']
                              XXXX']
&gt;&gt;&gt; vl = C.scene.view_layers['XXXX']
&gt;&gt;&gt; C.window.view_layer = vl
&gt;&gt;&gt;