I figured it out. Basically, the problem was that I also had registered a URL rewrite that set page_id
as a query var, which overrode the 404 and loaded the referenced page. I fixed this by adding this line to my throw404()
function:
unset($query->query_vars["page_id"]);