What was the reason behind destorying or re-minting counterfeit gold coins of the same karats as the real ones? I remember reading about an interesting event which happened in the early 19th century, in the Habsburg Empire.

A criminal organization, mainly composed of workers and corrupt administrators at a gold mine, minted prefect-quality gold coins illegally. Normally, the extracted gold had to be handed in, in exchange for a very low commission, so they handed in only part of the mined gold, minting the rest into coins illegally. However, instead of producing counterfeit coins with a lower than official gold content, they minted coins which had the same gold content as the real ones.

When the operation was busted, the confiscated coins were marked (by hammering a nail through them, if I remember correctly) and transported away to be destroyed, probably to be cast into bullion or to be minted.

This is what I don't understand, why was it necessary if the coins had the required gold content?

The criminal operation was definitely a loss for the government, but from the point of view of macroeconomics it shouldn't have influenced the supply of money. If the criminals wouldn't have minted it, I guess that probably the government would have. So, why were those "perfect" coins needed to be destroyed, if they were to be later re-minted anyway?
I don't know about the story you refer to, but I'd say this was likely due to the intrinsic fungibility of gold as a commodity, before it serves as money.

Besides its natural scarcity and the significant amount of energy it requires to extract and mint, other important properties of gold (to serve as real money later on, anyway) include:

being stable (phys. / chem. speaking), portable, divisible, and fungible.

Fungibility: both as a store of value and as a medium of trade, any one ounce of gold is (relatively) easy to recognize and test for authenticity, and thus easily interchangeable with any other ounce of gold, of same purity -- if one excludes other considerations such as numismatic value or tastes in shape, etc.

Because the operation in the story you recall was fraudulent to begin with (extra-minting undeclared on the books) it was then important to find a way to differentiate unambiguously those ounces from the rest that were duly kept on the books -- i.e., to temporarily "deny" that gold its fungibility, so to speak, and at the physical level (by mangling it) -- if only temporarily.

Of course the rationale was to prevent a priori those coins from going into circulation on the market, after the bust -- and whether or not the decision would be made later on to reintroduce them (but this time in a controlled way).

Just my understanding anyway.

'Hope this helps.