Real pilot here (albeit a student). The "detonations" that you hear when leaning excessively to the point of rough running are not "detonations" as such, but are actually cylinders being starved of fuel and not firing, while others still are. Even a really well tuned fuel injector setup will have some variation between the cylinders, so right before a total engine cut, that will happen. Running an engine like this isn't harmful to it, per se, but it's certainly not going to be happy running that way. I guess I don't really know if it would be harmful if left that way for a long time, as I don't think an actual pilot would ever leave their engine like that for long lol. It's actually how some people lean their engines, leaning to the point of roughness and then adding a little mixture. Hope this answers your question!
Some additional information: detonation happens in an engine when pressures and temps are excessively high and the engine is leaned to the point where there's just the right amount of fuel in the mixture to self-ignite prior to the spark plug sparking. The conditions required for this vary, but are typically above 65% power with high CHT's. The higher the % of power, the wider the band of potentially problematic mixtures is. The general advice is to be careful between 50 degrees ROP and 25 LOP when operating greater than 65% power.