Though now it is usually a business house that, under insurmountable financial difficulties, “goes to the wall,” it was, back in the sixteenth century, the adversary in a conflict that, forced to yield ground, went to the wall.
The allusion is to the desperate straits of a wayfarer when set upon by ruffians in an unlighted street of former years.
By giving ground and getting his back to the wall he was better able to defend himself by poniard or sword.
From the same situation, by no means uncommon in the Middle Ages and later, came our expression, “to be driven (or pushed) to the wall,” which we now use in a similar sense, to be forced to one’s last resource.