Yes, viruses can spread and infect computers simply from being on the same network. These viruses are called "Worms". They are fully automated, meaning they don't need any input from a user to activate, and they often spread without your knowledge. Worms can be spread through a number of ways: Some older worms would propagate themselves by sending copies of themselves via email, whereas others may exploit open ports on the network and send themselves using any form of transmission available. There have been quite a few major attacks by worms in the past if you want to do a quick Google search and read up on them.
Worms usually aren't a major threat for home networks. Usual targets would be public WiFi or places of business where an attacker can acquire lots of information from several people quickly. To protect yourself, don't download files from an untrusted network or website. Make sure your browser's set to request your permission before running pop-ups, files, or programs from the internet. Don't open files from people you don't know, or files from people who may not have a reason to message you directly (For example, Jeff Bezos isn't very likely to send an email with an attachment to one of the people on the floor putting things in packages, so don't trust this email). You can verify business emails are authenticate when they come signed with a certificate or signature, which should up promptly on screen (Though admittedly, lots of places don't use this feature unless it's standard practice). Scan files that you download with an anti-virus BEFORE opening them to verify they're safe. Install anti-virus software on your devices (There's an app for Malware Bytes for phones, too, that's pretty good).
Basically just standard good practices for protecting yourself from any virus, really.