In formal accounting, transactions should never be deleted or altered. Instead, when a mistake is made, the original transaction remains in the ledger, and a reversing transaction is added to the ledger. This reversing transaction restores the ledger to its state before the error, allowing the user to enter the transaction again correctly.
While a user can certainly enter reversing transactions manually,
GnuCash includes a menu option ( → ) that can quickly create the reversing transaction for you. This option only appears when you are in an account register. When you are in the transaction that needs to be reversed, all you need to do is select this menu item, and a duplicate transaction that reverses the active transaction is immediately created.
Once you choose the menu item, a reversing transaction is immediately created in the account using the current date. You may wish to locate the new transaction at the end of the register, and add explanatory notes to it.