To blow off steam is to dissipate stress
, distraction, or other (generally nonproductive) activities.
The term originates in reference to steam engines and related machinery - if the pressure of the steam in a vessel built up unchecked, it could exceed the capacity of the container walls, causing an explosion. In addition to killing or injuring anyone who happened to be near at the time, this would also turn your expensive, beautiful steamboat, locomotive, or power plant into an expensive, beautiful collection of functionless pipes and scrap metal. To prevent this, the mechanisms would be arranged so that when a steam gauge indicated a pressure differential approaching danger levels, a valve would open and steam would be vented ("blown off"), reducing the pressure to safe levels, and averting disaster.
Keeping true to the metaphor, it is implicit that in "blowing off steam", a more negative alternative is avoided, be it decreased functionality due to stress, or the possibility of more counterproductive behavior later. For this reason, nonproductive and "morally repugnant" activity is more often overlooked and accepted in this context. "After all," say the generals, "better the troops on R&R leave get drunk and patronize the local "working girls" than they keep it inside and in another month or two we've got another My Lai on our hands." You get the idea.