Because of electricity.
We just talked about the gel in an egg white, where the proteins were kept separate by their electrical charges on the outside of the molecule. Jelly is made of water in which huge molecules are dissolved, much like the protein molecules in egg white.
The molecules in jelly that make it firm are made of sugars that are all bonded together into huge tangled molecules made of many thousands of sugar units. Unlike starch, which is somewhat similar, pectins contain several different kinds of sugars.
Plants use pectins as building materials, to give shape and strength to their cell walls.
Pectins react to heat in a way almost the opposite of proteins. Where proteins unfold and connect to one another as the temperature rises, pectins do not. Instead, as the temperature gets warmer, the pectins bounce around against each other more, and lose their rigidity.
When we heat fruit and fruit juices that contain pectin, the pectins leave the cell walls and dissolve in the water around them. When the water cools, the pectins stop jostling and settle down next to one another, but still kept apart by their electrical charges. If there is enough sugar in the juice, the pectins firm up.
The result is a firm gel that you can poke, jiggle, and squish with your fingers or your tongue. The molecules are not strongly bound together, so the jelly is not a solid. But sugar and the large molecules of pectin lock up the water molecules around them, so they don’t flow like water. The result is jelly.