I wrote this on another thread on this site, but this problem is similar so i'll repost it here:
I had the same issue and none of the answers here worked, so i worked persistently to try and find other solutions. I found a solution that worked flawlessly, and is likely flexible if some people have the somewhat same problem but with a few different instances. You need to download NBTExplorer (download link here:
https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-tools/1262665-nbtexplorer-nbt-editor-for-windows-and-mac)
You can use it to datamine your minecraft world without loading it at all, no matter what version your world is. Just use the search function and search for a word that you're sure is a part of the command in the command block, and delete it, then save. This should remove the command from the world and fix the issue :)