I don't understand why magnetic fields and electric fields cannot
penetrate the cable when there is grounded shield covering the cable.
A magnetic field can certainly penetrate the shield but, we design cables so that they have symmetry and whatever influence the magnetic field has on the inner wire (e.g. a coaxial cable) also influences the other wire (or shield). We then used balanced receivers that are more than capable of looking at the wanted differential signal on a cable and ignoring (within reason) the common-mode electrical disturbance caused by the external magnetic field.
An electric field is much less likely to penetrate the shield but, it will act to "wobble" that shield voltage around. However, due to the nature of cables, the inner wire will also "wobble" around in sympathy because it's likely that the capacitance from inner wire to outer shield is much, much higher than the capacitance from the interfering electric field source to the cable. Again, a balanced differential receiver will do the hard work of ignoring the common-mode "wobble" whilst receiving the wanted differential signal correctly.
For unshielded twisted pairs (again, a properly designed cable type), the electric and magnetic fields equally influence both wires and thus do not produce a significant differential interference at the receiver.
Likewise, I cannot also understand why magnetic field from the core of
the cable cannot go outside when a shield exists.
It can if you don't drive the cable properly; driven properly, the magnetic field from the inner (i.e. coaxial cable) and the magnetic field from the outer shield will cancel at any distance beyond the cable. But, you have to drive the cable correctly and terminate the cable correctly. Clearly, twisted pairs also produce an externally cancelling magnetic field if driven correctly.