How does WordPress rewrite URLS using its PHP scripts

WordPress can make redirects internally, by wp_redirect() function. It is php code, for it to function, no redirect in Apache (httpd) or Nginx web server is needed.

Also, WordPress has own rewrite API, accessible via add_rewrite_rule() and similar functions. This is also php code, which doesn’t require any support from a web server.