The whole process is called osmosis. In it there is the flow of liquid along a concentration gradient. Water then flows from the side which contains the low concentration of dissolved molecules (this can be salts or sugar for example) to the side with the higher concentration until it reached equilibrium. This principle is shown in the image below (all images from the Wikipeadia article on osmosis):
The blue dots are the dissolved material, the concentration is high on the right side and lower on the left. Through the dotted line in the middle (which is a semi-permeable membrane) only the solvent can pass to reach a concentration equilibrium.
And this is exactly what happens to the yeast cells. The sugar crystalls get dissolved (at least partly) by some of the humidity from the yeast block (this will not work with dried yeast) and form a highly concentrated sugar solution (also called hypertonic). The sugar concentration inside the cells is relatively low (called hypotonic). This leads to the effort to balance the concentration inside the cell and outside of it which then leads to a massive efflux of water from the cells. This goes so far, that the cell membranes break and the interior of the cells is released (nucleus, DNA, proteins and so on) and the sugar is completely dissolved in the released water. The reason why this mixture is so "gooey" afterwards is the DNA, which forms long, thick strains.
This method can be used in the lab to break up cells relatively gently without applying too much force.
When baking you should make sure, that your yeast is not coming directly into contact with undissolved sugar (or salt which works the same way), as this will kill a part of your yeast cells. However, for baking you usually dissolve the yeast in water or milk, so there is a huge excess of water which dissolves the sugar (or salt) and protects the cells. Addionally your yeast is much better distributed in the dough and gives better results.