Can an iPhone get infected will malware by sharing a wifi connection with an infected computer? Can an iPhone Xs, not jailbroken, get infected with malware by connecting to the same Wifi network as an infected Macbook on the same apple ID account?
In theory any computer (including smartphones) is attackable over WiFi (or any other channel) as long as software has bugs which can be exploited to do so. Having a infected MacBook to start with, or sharing the AppleID between devices, may make it easier (or open additional attack vectors), but at the end it's always a weakness on the attacked device which makes it possible.