but the value change doesn’t get saved when I save the scene.
The class is derived from MonoBehaviour, the variable myBool is public. In fact, the value of the variable is saved correctly when I change it in the Inspector.
The question is now, is SetDirty only supposed to work in Editor-scripts, or should it work in this case, too?
No UnityEditor functionality is supposed to be used in any runtime/ingame classes such as a custom component or class derived from monobehaviour or scriptableobject. So any UnityEditor functionality is not guaranteed to properly work in any of these classes as well as you will get big problems when trying to build your game as the UnityEditor namespace is stripped out which will then cause compiler errors of any runtime classes using the UnityEditor namespace and the build will fail. Although you did include the Unity_Editor define, so you are good there.
To achieve what you want you should create a custom inspector for your component and use the SetDirty function with it.