After the @DMGregory♦ comment I come across [this](https://docs.unity3d.com/ScriptReference/EditorUtility.SetDirty.html) documentation.

So, to have the changes made through the editor API serialized correctly I did change this way:

    Undo.RecordObject(gameObjectInScene, "Set reference for itsField.");
    gameObjectInScene.itsField = theFieldValue;
    PrefabUtility.RecordPrefabInstancePropertyModifications(gameObjectInScene);

And if after changing the field you would like to apply the field change to a prefab just add a fourth line:

    PrefabUtility.ApplyPrefabInstance(gameObjectInScene, InteractionMode.UserAction);