One paragraph in Chapter 15 of To Kill a Mockingbird explains why Atticus brought an extension cord to the Maycomb jail.
A long extension cord ran between the bars of a second-floor winidow and down the side of the building. In the light from its bare bulb, Atticus was sitting propped against the front door. He was sitting in one of his office chairs, and he was reading, oblivious of the nightbugs dancing over his head.
Here's the explanation. There has been plenty of foreshadowing of potential mob violence earlier in Chapter 15. Atticus has decided to protect his client by spending the entire night sitting right out in front of the jail, and he has brought the extension cord to make sure that he will be clearly visible while sitting there, although ostensibly he is using the light for reading. The bright light, of course, will make any intruders clearly visible as well.
He is right in expecting trouble. Four cars filled with men arrive and stop in front of the jail. They are obviously a lynch mob, and Atticus is going to have to stand them off all by himself.
The description of the front of the jail illuminated by a single big electric buib is very effective. The reader can visualize the scene, with the nightbugs attracted by the light, and Atticus sitting there all alone. The extension cord was needed, of course, because there was no electric outlet on the porch. Atticus had to run the cord all the way down from the second floor. Unexpectedly, Scout intrudes into the confrontation and shames the men in the lynch mob into turning around and leaving. They might have worked up the nerve to attack Atticus, but they couldn't bring themselves to do so in front of a little girl who knew every one of them personally.