I've read that Yael slept with Sisra, but this obviously isn't directly in the text. What is the source for this and the reasoning behind it. Wasn't Yael married?
The source is Gemara Nazir 23b:
Summary: Rav Nachman said, a sin for the right reasons is as great as a mitzvah for the wrong reasons. We see this from Ya'el, who is described as being greater than Sarah, Rivka, Rachel, and Leah. R' Yochanan said: She had 7 acts of relations with him, based on the verse: Between her legs, he bent, fell, lay etc.
The Talmud derives this, as quoted and summarized, from the excessive description of how Sisra lay down. It is not explicit by any means, but hinted to in that way.
Nefesh HaChaim explains (in the end of Sha'ar Aleph ch. 21, in the end of Perakim ch. 7, and in Kesser Rosh 132) that the idea of "Avera Lishma" applied differently before the Torah was given to after, as before the Torah was given a person could make his own assessment (assuming he/she had the qualifications to do so) of what was "spiritually" the most beneficial, even if it contradicted the Divine concepts expressed in the mitzvos. However, after the Torah was given, we only have the Torah and one cannot do an aveira because they calculate it to be a good decision.
Nefesh HaChaim 1:21
Nefesh HaChaim Perakim 7
The story of Ya'el, he says, was an exceptional case because she was doing it to save the entire Jewish people, and was therefore circumstantially permitted. (It was explained to me that the greatness that the Gemara attributes was because even though she "got the chance" to do that which would be otherwise prohibited, she did not take the opportunity to savor it and she took no pleasure from it, as the Gemara explains). Nodeh B'Yehuda Tinyana Yoreh De'ah 161 makes basically the same point, and he specifically points out that this was not just an allowance of "saving a life" (Pikuach nefesh), as adultery is not permitted for that purpose, but was a specific exception of saving the entire Jewish people. He suggests that the proof for this is from Ester, who also submitted herself to extramarital relations for the salvation of the entire Jewish nation.
Therefore, the justification was the salvation of the entire Jewish nation.