Other answers show the etymology of "spanner" so I won't repeat that. But I'm not sure that anyone has attempted to answer the question.
What is being spanned is the gap between the faces of the spanner.
There are actually 2 different kinds of tools that in the US are called "wrenches". In the UK we give them different names.
This is not based on any research but is how I was taught the difference between spanners and wrenches as a child.
A spanner is a tool that has fixed parallel flat faces opposing each other so as to be able to grip an object of the appropriate size. Because it won't grip an object that's the wrong size, that fixed gap spanned by the faces defines the usefulness of the tool (hence the name).
A wrench in the UK is a slightly different kind of tool, one where an object can be gripped by two faces not simply as a result of their being rigid and the right distance apart, but by a force applied at right angles. A wrench will typically have two handles which need to be squeezed together (whether by hand or a spring) in order to grip something on the other side of a pivot.