Today, phones synchronize with google and microsoft accounts, and I don't know what else ... Accounts remember installed applications, passwords and visited pages, I do not investigate what your system is there, but check if it comes from there. On your computer, clean? Doesn't it show porn?
Second thing, do you also connect via the GSM receiver in the phone, or only Wi-Fi? You may have a worm on your home network, modem, router, not like that on your phone. The phone only displays pages sent by infected other devices.
How is the SD card on your phone checked? Such something as "my memory" in the phone, there is a separation in the phone memory between the place and data for the system and user data - format, factory reset does not have to delete all data, only those to the system, and user data, e.g. in my ex for separate selection and deletion.
As soon as via wi-fi is a topic rather for security and computers
https://www.elektroda.pl/rtvforum/forum217.html and for example
https://www.elektroda.pl/rtvforum/topic2874173.html, not GSM.