You use this to explain your actions, especially if they were unpopular, unkind or morally dubious. The idea is if you were defending yourself in court.
"I realise that wasn't nice of me to say that about her, but in my defence she had always treated me far worse."
"Yes, I kept your favourite book. In my defence, I had no way of contacting you to return it."