Sweetened condensed milk is a good ingredient for sweet recipes because of all the added sugar--about 25% by weight. But when sweetened condensed milk was invented in the 1800's, the original reason for adding sugar to the milk was not for flavor, but for protection against spoilage. And it works--even after you open the can, sweetened condensed milk keeps longer than fresh milk.
That added sugar kills bacteria that would otherwise digest the milk and spoil it. The sugar kills not by poisoning the bacteria, but by a more direct physical process. It draws water out of the bacteria so the bacterial cells shrivel and die.
Each bacterial cell has a sort of skin--technically, a membrane. Water can pass through this membrane pretty easily, but substances dissolved in the water can't.
Water has a natural tendency to move toward any region where there's a high concentration of dissolved substances. A bacterial cell in a can of sweetened condensed milk finds itself immersed in an extremely concentrated solution of sugar. Water inside the cell will, therefore, pass out through the cell membrane into the sugar solution. The bacterial cell dehydrates and dies in a sea of sugary water.
Sugar added to fruit has the same effect--that's the idea behind fruit preserves. Other foods are preserved with salt, exploiting the same principle.
That tendency of water to move toward a region where there's a high concentration of dissolved substances goes by the technical name of osmosis. In living things osmosis is one of the most important ways water gets from one place to another.