In 1790, the German poet J.W. von Goethe introduced the hypothesis that all the parts of a flower are derived from modified leaves. On this view, the sepals (the green, sheathing structures on the pink pictured above) and petals of a flower are leaves which surround the reproductive parts, usually with the goal of attracting insect pollinators, with an optional dose of attractive pigment. The stamens (male reproductive structures) are leaves which have developed specialized pollen-producing organs. The stamens in the water-lily pictured (the yellow structures) are more or less leaf-like, and it is easy to see how they might have developed from a primordial leaf. But where are the leaves on a pistil?
The flowering plants are more properly known as Angiosperms, from the ancient Greek words 'angeion', meaning 'vessel' or 'container' and 'sperm', meaning 'seed'. The pistil is the vessel: it houses the ovules and develops into the fruit. It can be seen in the centre of the hackberry flower on the left. The bulbous green bit is the ovary, where the ovules are found, and the two feathery structures at the top are the stigmas, which accept pollen.
One cannot tell just by looking at one plant how this structure could have developed from a leaf. Like many biological puzzles, the evolutionary origins of the pistil can only be discovered by comparative biology.
Imagine a narrow leaf with ovules attached along the edges. The Angiopteris fern pictured gives you the basic idea, although the structures along the margin produce asexual spores, not ovules. It is thought that these primitive seed leaves (called 'carpels', by the way) became rolled in on themselves as a way of protecting the ovules from either the elements or, more likely, hungry insects. This would form a sort of taco-shaped structure. The next step is for the margins of the leaf to fuse together, making a hollow tube (sort of a 'carpel tunnel syndrome', if you will. you won't? Ok, I'm sorry, stop hitting me.) Such pistils (called 'monocarpic': made from one carpel) are fairly common in nature: magnolias, legumes (peas and beans) and most members of the rose family all have them. They are also present in Amborella trichopoda, which is purportedly the most basal flowering plant. I've seen photos of Amborella which show the pistils incompletely fused at the margins, with the ovules peeking through. Most pistils, however, are made of more than one carpel: think of the different segments of a tomato in cross-section. Such a pistil is called 'syncarpic'; made of several carpels fused together. How do you get one of those? The answer is in the question: evolution acts to fuse a number of monocarpic pistils together to form one syncarpic pistil.
Its worth taking a few minutes to talk about placentation (i .e. where the ovules are attached to the pistil). Go back to our primitive seed leaves with the ovules attached around the margin. When they roll in on themselves, the ovules will be at the old leaf margins (the rounded part of the 'taco' facing in towards the fold). Such an arrangement is found in most monocarpic pistils; think of snap peas. If you take a number of these pistils and fuse them together at the margins, you end up with a pistil with the ovules anchored at the centre facing outward towards the edges. This is also found in a large number of syncarpic plants as well, as anybody who has ever carved up a bell pepper knows. However, the placentae have evidently moved around quite a bit over the course of evolution, and we often find ovules facing the opposite way (attached to the wall, facing towards the centre), all clustered at the top, all clustered at the bottom and all attached to a free-standing column of tissue in the centre of the pistil. What the evolutionary impetus of such changes might be is unclear (at least to me).
One last illustration: pictured (courtesy the Texas A&M Vascular Plant Image Library) is the fruit of the Chinese parasol tree (Fumaria simplex). At maturity, the carpels separate from one another into beautifully leaf-shaped units with the seeds attached to the margins, exactly as we imagined the primitive carpel. E. J. H. Corner made the point that if a fossil of this structure were discovered by a paleobotanist, she would just about choke on her rock hammer: a primitive, unfused pistil complete with marginal seeds!
All images courtesy Wikimedia Commons unless otherwise noted.