I understand cheating is shitty but it would make a lot more sense for the teacher to make this a teachable moment about cheating, and to promote collaborative solutions, but also checking work you get from others.
A huge part of development is copying code and reusing code from libraries. The important part is that you know how the code you copy works.