Delete default branch in organization repository via API results in 500

Deleting the default branch for a repository in my organization via the API results in a 500.

I have a repository, <org>/test with a default branch, main:

I run a command to delete it

➜ curl -w "%{http_code}" -X DELETE -H "Accept: application/vnd.github.v3+.json" -u "jtgrohn:<pat>"<org>/test/git/refs/heads/main

and it fails with a 500. However, it does actually delete the branch:

This is unexpected behaviour, because I expected it to delete the branch successfully - and give me a 204. If I go look at the branches in the repository, the branch is no longer there - the API errored after deleting the branch.

This also only seems to be an issue with repositories that are a part of an organization (possibly enterprise?). The exact same setup works as expected (returns a 204 and deletes the branch) with repositories under my user account:

➜ curl -w "%{http_code}" -X DELETE -H "Accept: application/vnd.github.v3+.json" -u "jtgrohn:<pat>"