I’ve solved around 100 problems on Trees in leetcode, and not once have I used the keyword delete. The delete keyword is simply not necessary while dealing with trees.
root = NULL makes the tree size 0. (i.e all elements deleted).
root = root->right deletes the root and the entire root->left subtree, there is no requirement to store the root in a temp pointer and delete it. Internally root->val is still stored in old address of root. But now that we have changed the address of root to root->right, the old value is simply forgotten.
Coming to your solution, for the input [2,1,3] the flow falls to the last if condition that you have written. temp is min(root->right) which eventually ends up becoming root->right.
Now root->val = temp->val which means your tree is now [3,1,3]. Finnally root->right = trimBST(root->right, 3, 4) which does no change to root->right, as the subtree is perfectly in range.
[EDIT] As for the runtime error I’m not very sure why, but I’m guessing it has something to with with the wrong use of the keyword delete or memory leak.