The following MF240 series printers are listed in About AirPrint - Apple Support (en-us, September 19, 2024):
- Canon MF242dw
- Canon MF244dw
- Canon MF245dw
- Canon MF246dn
- Canon MF247dw
- Canon MF249dw
So, I have to assume that your printer is AirPrint-capable, which is also indicated by the fact that your iPhone 8 could print (presumably without an additional app).
Use AirPrint to print from your iPhone or iPad - Apple Support
The first thing to try in a case like this is often a full power-cycle sequence (including the router).
Power off the Wi-Fi router, the printer, the iPhones, and all other devices/computers. Wait two to three minutes. Power on the router. Wait two to three minutes. Power on the printer. Wait a minute or two. Power on the iPhones and all other devices/computers.
AirPrint works with wireless (Wi-Fi) or wired (Ethernet) network connections. If you so wish, the printer can be wired by Ethernet to one of the LAN ports of the router instead (at least for a temporary test). Modern dual-band routers typically have "smart" device discovery and automatic Wi-Fi band selection, which sometimes can cause problems with printing (may require splitting/renaming bands). An Ethernet printer connection to the router may be more stable, and can avoid some of the difficulties.