The GameObject marked with HideFlags.DontSave doesn't get saved into the subscene scene file.
When the subscene is closed an entity scene artifact created by the asset importer is loaded. The problem is that internally to generate the entity scene artifact the asset importer opens the subcene and the user's OnEnable runs, creating the GameObject. Then the GameObject gets baked.
We can't change this behaviour internally, but AssetDatabase.IsAssetImportWorkerProcess() can be used to detect the subscene is being opened in the asset importer and skip the spawning.