I can't change the UI image canvas Scaler scale mode

I have no idea what you mean about adding / removing the canvas scaler, or changing its mode dynamically.

That is certainly possible, but I’ve never seen it be a useful thing to do.

Do as much authoring of your UI in the editor. Try to minimize scripting so that all you do is enable/disable entire hierarchies. To change stuff manually via code is extremely ticklish and inadvisable until you are total insane pro at using the UnityEngine.UI namespace of classes.

Here are some notes on UI Anchoring, Scaling, CanvasScaler, etc: