You can't /enchant something that can't normally be enchanted in survival mode, like putting Knockback on an axe, which is kind of silly to not allow being that it is a weapon, but you can use an anvil to put Knockback on anything, including literally a grass block, without even using cheats.
Steps to reproduce
Get a netherite axe and hold it
run /enchant @s knockback 2
❌ the command fails
3. Get a Knockback II enchanted book
Try to combine the book with the axe.
Notice The anvil allows it (and that the enchantment functions as it would with any other tool).
Linked issues
is duplicated by 2
Comments 4
/enchant was added before enchanted books were and the command uses the wording "[item] does not support..." suggests that that enchantment would be useless on the item when most items (Knockback for example) works properly on any item, I don't see why they would intentionally limit a cheat command to survival only applications
That's how it has been since addition; that it hasn't been changed in light of newer additions (anvils and enchanted books) is not a bug, but a change request.
This is a change request, and not actually a bug. /enchant is intentionally limited to survival-applicable enchantments (and has worked that way since addition). Anvils only bypass this in creative mode.
For feature/change requests, go to the feedback site.