### Godot version

v4.1.beta2.official [a2575cba4]

### System information

Godot v4.1.beta2 - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2070 SUPER (NVIDIA; 31.0.15.3141) - AMD Ryzen 9 3900X 12-Core Processor (24 Threads)

### Issue description

With the latest 4.1.beta2 static variables will now raise an error in console and log. No crash, only a error:
```
USER ERROR: Condition "p_elem->_root != this" is true.
   at: remove (./core/templates/self_list.h:80)
```
I don't know if pull #78138 has anything to do with it?

Anyway, if `static` keyword will removed, the error is gone.

### Steps to reproduce

Pretty simple:

Make a new scene, attach a new script and copy/paste this:

```GDScript
extends Node2D

static var my_static_int: int = 0

func _ready() -> void:
	pass
```

Run scene and close it.

### Minimal reproduction project

N/A
err = parser.parse(source, p_path, false);
	const GDScriptParser::ClassNode *c = parser.get_tree();
	if (!c) {
		return String(); 
	}
	/* **WARNING**
	 *
	 * This function is written with the goal to be *extremely* error tolerant, as such
	 * it should meet the following requirements:
	 *
	 * - It must not rely on the analyzer (in fact, the analyzer must not be used here),
	 *   because at the time global classes are parsed, the dependencies may not be present
	 *   yet, hence the function will fail (which is unintended).
	 * - It must not fail even if the parsing fails, because even if the file is broken,
	 *   it should attempt its best to retrieve the inheritance metadata.
	 *
	 * Before changing this function, please ask the current maintainer of EditorFileSystem.
	 */
	if (r_icon_path) {
		if (c->icon_path.is_empty() || c->icon_path.is_absolute_path()) {
			*r_icon_path = c->icon_path.simplify_path();
		} else if (c->icon_path.is_relative_path()) {
			*r_icon_path = p_path.get_base_dir().path_join(c->icon_path).simplify_path();
		}
	}
	if (r_base_type) {
		const GDScriptParser::ClassNode *subclass = c;
		String path = p_path;
		GDScriptParser subparser;
		while (subclass) {