For this show only, to more easily film the jail house break in/shoot-out, the back door of Matt's office is now directly on the back wall of the jail cell area. In the next show,the original cell is back in it's place. Also in this episode, there is a cell across from the one Billy is in. Usually, it is a blank wall, on the other side of which is Matt's cot.
Just prior to the attempted jailbreak, Ed is talking to Billy through the cell window. He could've easily passed a gun to Billy to either assist with the jail break by shooting whomever opened the door, or later by feigning an illness, and when the cell door was opened, pulling the gun on whom ever opened it.