Dally gives them the gun in Chapter 4 of The Outsiders.
After the Socs attack and Johnny kills Bob, Dally meets them, provides money, a loaded gun, and directions to hide in the abandoned church.