This is another common use of VPNs. As @BigT says, there is lots of phone software that pretends to be a VPN, because that is the only non-jailbreak method of hijacking the phones network connection. The software then can implement DNS based ad block lists, and some have more sophisticated firewall type function.
However, I don’t use software like that, because I want to run a real VPN, and the phone only allows one VPN at a time. The better, but more difficult to implement, solution is to redirect your phone’s DNS to a DNS-over-HTTPS or DNS-over-TLS server that uses a DNS based ad blocking list.
Modern Android and IOS both have ways of configuring DoH (only on IOS) or DoT (on both). This has some downsides. The two biggest are that it can interfere with captive portal type WiFi logins, and that ad blocking can break some websites and apps.
On both systems, temporarily disabling private DNS and using the default one provided by whatever network you’re on is pretty easy. The hard part is recognizing the cause of the problem and taking steps to correct it. For example: login to Wi-Fi network, captive portal login won’t load, disconnect from Wi-Fi, disable private DNS, reconnect to Wi-Fi, login at captive portal, re-enable private DNS. If that’s something you do frequently it can get annoying, but for the rare hotel stay or whatever, it isn’t a big deal.
For my private DNS I use a pi-hole in the cloud that I control. The only good reason to do it myself is I can control the block lists. There are several free and paid services that will do similar, such as AdGuard, linked below.
The ad blocking is not perfect, but it is pretty good, and has the large advantage of blocking ads in any app, not just while browsing.