Skip Connections in Residual Modules
Residual blocks contain weights as you can see in this overview of some different variants:


Source: this blog post

Since weights are learned parameters the neural net can learn to use or not use non-skip/non-identity paths, i.e. by optimizing with gradient descent the network can learn to skip these blocks (or not). 

To phrase it differently: the networks "knows" by following the opposite direction of the gradient.