This usage dates back to Middle English; the relevant definition in the OED is:
4a. From (something) as a cause or motive; as the result or effect of; because or by reason of.
The earliest example is:
Eleuſiuſ iherde þiſ. & feng hiſ neb to rudnin ant tendrin ut of teone.
Þe Liflade of St. Juliana : from two Old English manuscripts of 1230 A.D.
Elusisus heard this and began to be red of face and to burn out of vexation.
Translation: Early English Text Society: Original series
This same thing is noted in the book Old and Middle English:
The ut of is used in a new sense, where the mental cause of an action is to be marked; a tyrant began tendrin ut of teone, 'to burn, out of annoyance'
There are several senses of out of that predate this one according to the OED, such as "1a. From inside (a containing space or thing)" (modern example: "draw a number out of a hat") and "3a. From a place or thing as a source, origin, or provenance; deriving from." (modern example: "paid it out of my own pocket"). They all have to do with specifying where something is coming from, which is no different than the sense in question.
If you don't have access to the OED, you can also reference the Middle English Dictionary.