As the title says, I created a world and set it as a swamp with 63 layers of dirt to ensure that the swamp hut can be spawned at the right height. But some other hostile mobs were spawned in the special area of the hut. In screenshot 2021-08-05_10.47.39.png, I replace the blocks around the chunk where the hut is located with air, and placed slabs on some blocks outside the hut area in this chunk to prevent redundant spawn. It can be seen that a skeleton was spawned on the roof of the hut. This chunk is located in [48, ~, 96] (obtained through the / locate command).
Then I made some other attempts. I created a new world of single biome, used the same seed, and still set it as a swamp. A hut was also generated at the same location in the world. After testing that witches can be spawned there normally, I copied the level.dat of this world to the folder of the custom world. Then I tested the custom world again. As shown in figure 2021-08-05_11.04.02.png, a witch is spawned normally. I'm not sure how much this will help to find the cause of the problem (I'm not professional about it), but I guess the chunk data is stored correctly, and there may be some problems with the chunk structure detection mechanism of the custom world (or the simple witch generation mechanism).
At first, I found this problem in 1.16.5, so I repeated all the tests in 1.17.1, including rebuilding the world. All worlds use the same seed.
Files 2021-08-03_ 22.13.21.png and 2021-08-03_ 23.48.38.png are screenshots of the test in 1.16.5.
I uploaded the JSON file of the custom world. You can import it to rebuild it when you create a new world.