When this happens, there are two things a player can do about it: build a new tool and try enchanting it again or disenchant it and try again. Disenchanting is a more resource-friendly solution, the steps to which will be broken down below.
RNG’s bad side: Bad Minecraft enchantments and how to undo them
1) Crafting or finding a grindstone
A more lucky route would be to find a village with a weaponsmith, as a grindstone is a guaranteed spawn in that structure. If the player does find a grindstone in a village, they will either need to do their disenchanting in the village or use any pickaxe in order to take the grindstone.
The other, easier way to obtain a grindstone is to craft one. This can be done with two of any wooden planks, two sticks, and a single stone slab. For clarification, this is a normal stone slab, not a cobblestone, so the player will need to smelt at least three cobblestones in a furnace to make the correct slab.
2) Disenchanting with a grindstone
To use a grindstone to remove an enchantment, a player simply needs to right-click the grindstone to enter the interface. Then place the enchanted item in one of the two boxes on the left-hand side, and retrieve the now disenchanted item from the righthand side of the interface.
Disenchanting does return some experience to the player. This process will not return the full amount of experience spent on the enchantment but will instead return a small portion of what was used.
The amount returned depends on both the number of enchantments and the levels of said enchantments on the item, but there is also a random range. This means there is no way to know for sure just how much experience will return on disenchantment.
3) Tips and other useful grindstone information
It is important to note that a grindstone cannot remove curses, so if a player is hoping to remove a curse from a good item, there is no way in vanilla Minecraft, as of 1.18, to do so legitimately.
Also, grindstones do not remove custom names given to items with nametags. To change the name of an item, a new custom nametag needs to be made, and then combined with the item at a Minecraft anvil.