Python, what is the right context for bpy.ops.transform.delete_orientation() operator
You need to override the context of the operator:

import bpy

name = 'Edge.001' #The orientation to remove

views = [area.spaces.active for area in bpy.context.screen.areas if area.type == 'VIEW_3D']
if views: #Assign the orientation in the view so that it is active and can be removed
    views[0].transform_orientation = name

areas = [area for area in bpy.context.window.screen.areas if area.type == 'VIEW_3D']

if areas: #Give the good override context
    override = {'area' : areas[0]}
    bpy.ops.transform.delete_orientation( override )


Edit: following the comment, some 'novice' explanations

Operator's context can be override. An override is a dictionary with some keywords. Among them you have the 'area' (because we have bpy.context.area). And if you look in the N panel where a custom orientation can be deleted, you see you are in the view3D area.

So... we just need to give a view 3D area to the override context.

Edit again:

What you did in your code is changing your current context (the view itself)... but that does not change the execution context itself (where delete_orientation is called), that is changing only the view.

More information here



Update:
In order not to get a ( Pycontext '' not found ) error in the system console, it's better to write the code this way:

...
if areas: #Give the good override context
    override = bpy.context.copy()
    override['area'] = areas[0]
    bpy.ops.transform.delete_orientation( override )



Reference: here