Can application DNS requests bypass a firewall on Windows and Linux
It depends on the policy enforced by the firewall.  If it blocks outbound DNS requests, then the request wouldn't go through; if it doesn't, the request would go through.  A firewall is a mechanism; it has to be configured with a policy that determines which packets or connections are allowed and which are blocked.  Just saying you have a firewall does not tell us what policy you have chosen to have it enforce.
The details of how gethostbyname() behaves are beyond the scope of this site.
You certainly could have a situation where the firewall blocks an application from making DNS requests to the outside world but allows them to a local DNS server; and where the local DNS server acts as a resolver or a proxy and itself makes requests to the outside world.  That will depend on the firewall and how it is configured as well as the DNS server and how it is configured.