Where does Android get its DNS information when connected to Wi-Fi?
Thank you all for the comments. They helped me work it out.
I'm not 100% sure of the cause of the behavior. It stays even when I switch off 4G and restart the phone. In the post linked to by Irfan Latif it is suggested that Android favors IPv6 dns servers. That could be the cause since my network is IPv4 only.
But the hairpin NAT provided the solution. (Called NAT Reflection in pfSense) After enabling this, things started to work.