I'm pretty confused about what you're observing. Did the Mac's screen get "taken over" as soon as you rebooted? Or did it only happen once you've launched a browser?
Infecting an iPad while it's turned off is quite a trick (i.e. my skeptical flag has been raised pretty high). Note a "locked screen" is not turned off. That's just a low power mode with the screen off (usually locked). Some background processing is allowed in this mode.
Most likely though ... I can imagine that if your browser settings (bookmarks) are sync'd between the Mac and iPad (via sharing Safari info with iCloud on both devices) ... then if Safari on your Mac has been screwed up, those settings could be shared with the iPad the next time you used it.
But ... otherwise I'm drawing a blank how your iPad could have been "infected" while turned off (we'll ignore Pegasus for now, it's not likely you were a target of the people that had that available, and they didn't try and scam with an 888 number).
If the offending source was really something on the network, then any number of changes could have been responsible for it going away. E.g. an infected web site should have been shut down (or added to Apple's block-'em list). Or the domain-name system could have been fixed (e.g. routing "www.cnn.com" to an offending site).
Of course the very last thing you every want to do is call the 888 number for "help". They're the bad guys.
It wouldn't hurt to make sure that all your Apple devices are running the latest software. And .. make sure your internet router (usually a WiFi base station) is also updated to their latest firmware.
If you don't know how to check, get some help