This is a corner case of the SPARQL protocol. I will be happy to help with a patch. Probably the fix at RDF4j can be adapted without to much effort.
curl -D /dev/stderr \
-X POST \
'https://sparql.api.identifiers.org/sparql' \
--data 'query=PREFIX%20rdfs%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0APREFIX%20owl%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F2002%2F07%2Fowl%23%3E%0ASELECT%20*%20WHERE%20%7B%0A%20%20%3Chttp%3A%2F%2Fpurl.uniprot.org%2Funiprot%2FP05067%3E%20owl%3AsameAs%20%3Fnamespace%20.%0A%7D' \
-H 'Accept:application/sparql-results+json' \
-H 'content-type:application/sparql-query'
Should return a result not a 500 error.