Summary
When a world contains a datapack that adds a custom dimension, removing the datapack afterwards causes the world to fail loading with an error. The world should be able to load normally even after datapack removal.
It's really quite annoying, I've had quite a few players come up to me with the problem. And they're stuck playing with datapacks forever.
Steps to Reproduce:
Create a new world in version 1.21.7 with a datapack that adds a simple custom dimension
Launch and enter the world successfully
Disconnect from the world
Remove the datapack from the world's datapacks folder
Attempt to reload the world
Observe that the world fails to load
Expected Result:
The world should load normally, ignoring the missing dimension.
Actual Result:
The world fails to load completely.
Root Cause Analysis:
Minecraft appears to search for the dimension key via the level.dat file and cannot find it, consequently preventing world launch. The issue occurs in the WorldGenSettings > dimensions > foo:bar
 path in level.dat.
Screenshots and the test datapack are attached to demonstrate the issue.
Proposed Solution:
When a resource location for a dimension is missing during world loading, the corresponding entry in level.dat should be automatically removed. If the player later re-adds the datapack, this would have no negative impact as the dimension field would be regenerated.
Since this involves constant information only, removing it should be safe.
Environment
Minecraft Version: 1.21.7
World with custom datapack dimension
Windows 11
Can confirm, but this is invalid per this comment.