For this to be a valid pedagogical technique it has to be applied properly for the intended student. As described in the linked article for middle elementary aged students it seems effective. I can easily imagine my own middle elementary aged child responding well to it.
Your experience however seems to be either in secondary or collegiate classrooms and I can easily see where this approach there would often be problematic. That said if an instructor is trying to get students to engage in critical thinking about why something works then an intentional mistake could be educational. You can copy code from stack overflow all day long but it’s going to work a lot better if you can actually analyze it and understand what’s happening.
Your experience however seems to be either in secondary or collegiate classrooms and I can easily see where this approach there would often be problematic. That said if an instructor is trying to get students to engage in critical thinking about why something works then an intentional mistake could be educational. You can copy code from stack overflow all day long but it’s going to work a lot better if you can actually analyze it and understand what’s happening.