Last game my enemy killed my nydus network when I had a ton of units inside it. I thought the units would come out or something, but they disappeared. He killed me so I didn't have the possibility to try it out, but what happens if I build it back? Did those units get lost?
Firstly a reminder on terminology.
Nydus Network - This is a building morphed from a drone. Nydus Networks summon Nydus Worms. Nydus Worm - This building is built from Nydus Worms.
It's probably better to say that units are inside the Nydus system, instead of inside a Nydus network. Using the term "Nydus network" to describe the place where units are stored can be confusing since "Nydus network" is a building.
If all your nydus buildings (both nydus networks and and nydus worms) have been wiped out, then you lose all the units inside (as per Resorath's answer). Even if you rebuild some nydus networks and nydus worms later, you no longer have access to those units.
You can save units inside a nydus system if you have nydus network that is in the process of being built when all the other nydus buildings are destroyed. When the other nydus buildings are destroyed, the units are saved within the nydus network that is being built, and can be unloaded when the building is completed.
This does not work when summoning/building a nydus worm. When the nydus network that is summoning a nydus worm is destroyed, the partially complete nydus worm will cancel and disappear (refunding 75% of the cost).