It does that because creating a memorial is not the same as deleting the world. A memorial is saved in a different directory, and not deleted when you delete the world.
And the error was not bad programming, but bad testing.
Unless you mean something else, aka, a different bug message. In that case I don’t know what you are talking about. Please, could you post the error message here? And the steps you took to get to the error message? (And your game version, OS, language settings, and other small bugs you encounter).
Due to the immense amount of game variant setups, computer setups, and ways of interacting with the system, we cannot ‘walk’ all the code paths. So there will always be bugs. The ‘good’ programming choice would be to just throw out all less used options. Like crawl stone soup does. But this is not the CDDA way. And yes, that create a bit more buggy game, but quite an interesting game experience (not the bug, but the game itself).