A very interesting idea. I would love to see how this is resolved.
A script cannot change the theme specified for a layout. This is something that can only be specified manually while in layout mode.
But there are ways to dynamically change the background color of a layout. It is also possible to use duplicate layout to make a copy of the layout where you then specify a different theme for the copy. A script can then select one layout or the other.
One way to change the background color dynamically is to place a conditionally formatted "do nothing" button or an empty field or a layout text object on your layout, behind all other objects and sized to fill the body layout part. The conditional format expression can then dynamically control the fill color of this layout.
An "old school" method that we used to use was to cover the layout background with a container field into which we had inserted a solid color rectangle with the "enlarge or reduce contents" options specified and the "maintain proportions" check box cleared. By putting different rectangles in the field we got different color backgrounds. This was the precursor to conditional formatting. (This container field was actually a calculation field with "container" specified as the result type. The calculation selected the contents of one of several global container fields that each stored a different color rectangle object.)