Heavy cream is what is called an “emulsion”. An emulsion exists when tiny droplets of one type of liquid are floating around in another type of liquid that does not like to mix with the first. In the case of heavy cream, tiny globules of fat are suspended in mostly water. By shaking the heavy cream in the jar, you are forcing the fat globules to slam into one another. If they hit each other with enough force, they will simply stick together, the fat collection becoming bigger and bigger with each extra globule. After enough shaking, the fat globules form a chunk of butter.