The shape of a clover, like any organism, is determined by its genes and its environment. The genes provide a blueprint for the shape (and many other characteristics) of the plant while the environment modulates the way the blueprint is turned into reality.
The information that a typical clover has three leaves (or to be botanically more precise for once: that each clover leaf has three leaflets) is stored in its genes and inherited from generation to generation. Scientists know a lot about how this information is read and used when the clover grows out of its seed, but many details remain to be discovered. There seems to be a particular gene which could not be pinpointed yet and which ‘tells’ the clover to stop making more leafs when there are three. In some clovers this gene is present in a slightly different version which makes it a bit ‘leaky’. I.e., it only whispers ‘stop’ instead of shouting, so the clover continues making more leaflets: four, five, six, or even more.