To me, the role of the fool in King Lear is to be Lear's conscience. The fool, who only appears in about half of the play, is constantly badgering Lear to admit that he has made a mistake. The fool keeps telling him that Cordelia was good and that Regan and Goneril were not. When Lear goes mad, the fool disappears, which makes sense because insane people lack reason and therefore their consciences can't reason with them.
The role of the fool in this historical period was similar to that of the character. They were meant to provide comic relief within the household of a noble or other rich person. But they were also meant to some extent to prick at the self-importance of the people in power.
In virtually any play it is necessary for one character to have another character to talk to. This is how information is conveyed to the audience. A good example is the two clowns in Waiting for Godot. The message would be the same with only one character waiting for Godot to arrive, but there would be total silence on the stage--unless, of course, that character indulged in soliloquies. Many characters seem to have been created just to give the main character someone to share his thoughts and feelings with. This probably explains why Macbeth has Lady Macbeth as an accomplice. Horatio serves that function in Hamlet. The Fool serves that function in King Lear, especially as someone to whom Lear can express all his burgeoning feelings. Lear has no one else to confide in. The Fool is loyal, of course, but he also stays close to Lear because the King is his protector and his bread and butter. Fools were able to get by with all kinds of insults and practical jokes because they had powerful protectors--but they must have made a lot of enemies who would take their revenge if a fool fell out of favor.
The Fool must have had a very hard life before he had the miraculous good fortune of being taken up by the king. The Fool often seems much wiser than Lear, but this is mainly because he has experienced the way people behave towards others when they have nothing to gain or to fear from them. Lear has always led a sheltered life, whereas the Fool got his education in the School of Hard Knocks. Throughout the play Lear is learning what the Fool already knew.
The Fool is Lear's own stand-up comedian, sure, but more interestingly, he's the only guy that Lear allows to criticize him. (Remember, when Kent lips off, Lear boots him out of the kingdom and when Lear doesn't like what Cordelia has to say, Lear disowns her altogether.)
As in many of Shakespeare's plays, the Fool is actually really smart – and the only person who tells it like it is. Compare Lear's Fool, for example, to Feste in Twelfth Night – neither one of them are afraid to call their misguided masters "foolish" and they both function as characters that provide a lot of social commentary. At the same time, the Fool is more than just a funny and brutally honest guy; he's also loyal. Along with Kent/Caius, the Fool braves the elements (which at times consist of rain, thunder, and lightning) with his master.
But the Fool is also a big mystery: what happens to him? He disappears after Act 3, Scene 6, and nobody ever explains where he's gone. The only possible reference to the Fool after that is in the final scene, when King Lear says "And my poor fool is hanged" (5.3.17). This could mean a couple of things: 1) Lear might be referring to Cordelia with a pet name, "fool," since Cordelia has just been hanged by Edmund's goons. 2) Lear could be literally talking about his Fool – perhaps the Fool was also hanged by Edmund's henchmen or, perhaps he hung himself out of despair. It's hard to say what really happens to the Fool. Some literary critics even speculate that the Fool and Cordelia were played by the same actor. They never appear onstage together, so some scholars hypothesized that the part was double cast, and that the Fool had to disappear when Cordelia came back into the play.