My understanding of the expression is this: In small arms, it applies to semi- and fully automatic weapons. There is usually a part in pistols, at least, that prevents both full auto fire (maybe) and firing with the breech not fully closed (for sure). That part is called the disconnector. Naturally the breech has to be closed for safety's sake upon firing.
If the slide or the barrel (or both) of an automatic pistol is pushed back, it should not fire, though I don't know what the critical distance is. If it's back, it's said to be "out of battery." The same expression could be said of an artillery piece that is either not emplaced or otherwise set up for firing or, with some older guns, the tube is disconnected from the recoil mechanism and moved to the rear for travelling purposes. That was done even before recoil mechanisms existed. In modern guns, the recoil mechanism also "returns the gun to battery."
I suppose the same conditions apply to other firearms but I've not seen the expression used for anything else, even though the very same conditions are there, sort of. In fact, the M16 was even given a built-in device that is still there to assist in making the bolt go forward "into battery," though again, I've never read of anyone actually using it for that purpose. I suppose the manual says that's the first step in applying "immediate action."
Now with an automatic, if it doesn't go into battery, you could hit the back of the slide (but not the hammer). That probably isn't recommended and I don't think I've seen it in any manual, all of which probably assumes away that problem. Perhaps others here could elaborate on that point.