During the Medieval period, blades tapered significantly in response to development of mail and full plate armour, to be able to target joints and with such narrow blades, break links of mail when thrusting into such areas. However, in the civilian context the need for a narrow and stiff blade seems unnecessary as both parties would be unarmoured. The hand protection is nice but basket-hilted broadswords achieved the same protection and were able to cut and thrust well. Was it because people's clothing was difficult to cut through? Why did the rapier become so popular?
To start with, the rapier is not an armour-penetrating weapon, and not all swords that are long and thin are made to pierce armour. Rapiers themselves have a number of characteristics that show their civilian nature.
Now, some longer, thinner swords are made for piercing through the gaps of armour in war. The most extreme example of this is the Estoc a long, stiff, thin sword with an acute point and no edges at all - a pure thrusting weapon. This may sound a bit like a rapier, but it is solely a weapon for armoured fighting on foot in war and tournament, and it is meant to be used two handed, often half swording to find the gaps in armour. While rapiers have edges (and earlier proto-rapiers were used to cut), estocs have no edge at all, and often have a triangular or square cross section, like the awl point on a polearm head. Perhaps we could view estocs as an indirect inspiration of rapiers, but one way in which they are related is that any sort of long thin sword requires higher-quality steel construction, and in the 15th century all-steel, often single-piece swords increasingly replace blades made of steel and iron, or made of multiple pieces. The same technology that made estocs possible made rapiers possible 50 years later.
In contrast to Estocs, and rapiers many of the more 'normal' swords that seem intended for penetrating the gaps of armour aren't particularly thin, though they might be long. Many are triangular or are trangles with slightly curved sides. Many, many swords of this sort are 30" or under, including the famous sword from the tomb of Henry V and many of the swords from the Castillon finds, illustrated above in groups. Shorter and longer swords seem to have served beside each other on the battlefield - someone better versed in fencing manuals can confirm my suspicion that these personal preferences probably came down to reach versus quickness and maneuverability. The longest single-handed late medieval swords are around 36" long and still have a decent blade thickness, like this nearly 35" example at the Wallace Collection. Rather than a very long, mostly straight-sided blade like a later rapier, it is a blade that is very acutely tapered; while still a thin sword it has a thicker base than a rapier. The reason for this is is that if you're thrusting into the gaps of armour (especially trying to penetrate mail) you need that acute point to act as a wedge to thrust in, and you need a blade that is stiff and won't bend. An estoc, without the need to be sharp on the edge, could have a cross section that was thick in all dimensions - a flatt(ish) blade of a two-edged sword will need to be broader to get the same stability and strength. Writing in 1590, the retired English Soldier, proto-nationalist and all-around curmudgeon John Smyth wrote that rapier blades "...being so narrow, and of so small substance, and made of a very hard temper to fight in privat frays, in lighting with any blow upon armour, do presently break, and so become unprofitable." To conclude, there are fairly long, fairly thin swords for war that may well be intended for thrusting threw gaps in armour, but their blade shape is broader and 'pointier' than later rapiers.
There -were- some later medieval swords that were less pointed and still rather long. You begin to see more of these in the later 15th century and early 16h century, such as this example and This one, both at the Wallace collection in London. Also in the 15th century you see the development of more involved protection for the hand, such as this Italian sword from before 1432 and the characteristic double-ringed Iberian hilt of the later 15th century on this sword attributed to Ferdinand the Catholic.
In the early 16th century (and even the later 15th, perhaps) swords roughly like this - longish, pointy, good for war or for civilian self defense - began to be worn with civilian clothes in a wider variety of circumstances in Italy and Spain (in the Middle Ages, swords were mostly carried by soldiers or travellers - municipalities tried to ban or otherwise discourage the carrying of swords in cities and towns, for fear or violence). It is likely that a Spanish term for this, Espada Ropera or 'sword of the robe' (sword for civlian dress) is the origin of the term 'rapier.' But at first these swords were very similar to or identical to military swords. The classic rapier - incredibly thin blade with an acute point, complex hilt, worn with civilian dress, fighting in a style that emphasized the point - had emerged by the mid 16th century, by which time people are alternately singing its praises and condemning it as the murderous and militarily useless tool of urban feuds. Unlike previous swords, it was exceptionally long and while it was very pointed it was not tapered like the mail-piercing swords of the 15th century, nor was it as sturdy. A large factor in the development of its pointy, incredibly long form and its adoption was the new philosophy of fencing established by Camillo Agrippa and Camillo Palladino. These masters held that thrusts were the most efficient attacks, and lunging and otherwise extending the reach made thrusts quicker and deadlier. This system of thrusting from a relatively significant distance called for a longer sword that was optimized for thrusting. Thus, the rapier as we know it. Its length is for reach, not for sliding into the gaps in armour, and its design for the thrust is to allow for quick attacks, not the penetrate mail.
The rapier spread along with this system of fencing, as well as another custom: The civilian duel. Wearing swords, and defending one's honor by dueling, became a way for men to proclaim themselves as socially important and worthy of respect. This was particularly true for untitled men with pretensions to more elite status (landed but untitled gentlemen, merchants, professionals). Wearing swords and dueling went hand in hand (guantlet?) - men wore swords to declare that they were honorable men willing to defend their honor, and they fought duels to prove it. The rapier and its attendant customs were adopted in France and more reluctantly in England and Germany. It's important to keep in mind that in the era of the Renaissance Italy was a trend-setter in so many ways - the arts, fashion, science and also the semi-martial customs of the aristocracy. These imported trends had their share of detractors, such as Smythe and the English fencing master George Silver.
And what did the rapier look like by say, 1600? It was often incredibly long. Where the single-handed swords of the Middle Ages 'max out' at around 36" (90 cm or so) and many are under 30" long, many rapiers are over 40" (100cm+) long, longer than most medieval 'bastard' swords, much less single-handed swords. Being made to thrust, not cut, they could afford to be long and thin. The fencing masters themselves talked about proper sword length. Ridolfo Capo Ferro in his 1610 work on fencing derided swords that are too long and malproportioned to the wielder's body, but then recommended that the ideal sword was twice the length of a man's arm! This gives a length of somewhere around 140 cm on average, or a blade more than 55" long, well over 4 feet. And indeed, there are surviving 17th century rapiers that are that long. However, their sheer length and thinness made them less than ideal military weapons, as Smythe says. They are best seen as the highly specialized product of the purpose they were designed for - fencing in an unarmoured, civilian context, using a system fencing that emphasized lunging thrusts that required a great deal of reach.
Sources:
Ewart Oakshott - Records of the Medieval Sword
Alan Williams - The Sword and the Crucible
Tobias Cawell - The Noble Art of the Sword Much of this answer is heavily indebted to Capwell's description of the rapier's development and spread.