How to destroy objects in editor mode in OnValidate event?

GameObject.DestroyImmediate(o);

Destroying GameObjects immediately is not permitted during physics trigger/contact, animation event callbacks or OnValidate. You must use Destroy instead.
UnityEngine.Object:DestroyImmediate(Object)

– ok, i’ll use Destroy –

GameObject.Destroy(o);

Destroy may not be called from edit mode! Use DestroyImmediate instead.
Also think twice if you really want to destroy something in edit mode. Since this will destroy objects permanently.
UnityEngine.Object:Destroy(Object)

WHY???

private void OnValidate()
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.delayCall += () =>
{
DestroyImmediate( GetComponent() );
};
#endif
}

Sounds like what you need here is EditorGUI.BeginChangeCheck.

	string str = "";
	public override void OnInspectorGUI ()
	{
		base.OnInspectorGUI();
		EditorGUI.BeginChangeCheck();
		EditorGUILayout.TextField(str);
		if(EditorGUI.EndChangeCheck())
			Debug.Log("string changed");
	}

DestroyImmediate will work when called from OnInspectorGUI. Remember that DestroyImmediate(this); will cause a Unity crash.