How do I automatically remove anvils in Minecraft?

If the total cost to repair an item is greater than 39, it cannot be repaired in survival mode. You can use the RepairCost nbt tag to make it too expensive to repair an item in an anvil. For example, this command will spawn a Power 10 bow that cannot be repaired with an anvil:

/give @p minecraft:bow 1 374 {ench:[{id:48,lvl:10}],RepairCost:40}

Set a command block with a comparator clock that runs:

/clear @a minecraft:anvil

This will always clear out any anvils any player has in their inventory. The player won't get the items back, but it should be punishment for making an anvil