A PiHole functions has a full DNS server. You can configure it to serve any arbitrary records you like - which is basically how it overrides ad domains to prevent them from loading.
So, if you know the IP address that a particular domain is supposed to route to, you configure the PiHole to respond with that IP address for that domain. So, it doesn’t matter that the major DNS servers return junk because your PiHole never asks them.
This is, effectively, how oral flee/tick medications work in animals. It basically turns the animal’s blood into a mild poison. The poison is mild enough that it doesn’t affect the animal but it’s enough to kill small insects like flees, ticks, or mosquitoes.