Volume 3, Book 34, Number 420 :
Narrated by Abu Huraira (radiallaahu `anhu)
The Prophet (sallallaahu `alayhi wasallam) said, “The Prophet Abraham (`alayhissalaam) emigrated with Sarah and entered a village where there was a king or a tyrant. (The king) was told that Abraham (`alayhissalaam) had entered (the village) accompanied by a woman who was one of the most charming women. So, the king sent for Abraham (`alayhissalaam) and asked, ‘O Abraham! Who is this lady accompanying you?’ Abraham replied, ‘She is my sister (i.e. in religion).’ Then Abraham (`alayhissalaam) returned to her and said, ‘Do not contradict my statement, for I have informed them that you are my sister. By Allah, there are no true believers on this land except you and I.’ Then Abraham (`alayhissalaam) sent her to the king. When the king got to her, she got up and performed ablution, prayed and said, ‘O Allah! If I have believed in You and Your Apostle, and have saved my private parts from everybody except my husband, then please do not let this pagan overpower me.’ On that the king fell in a mood of agitation and started moving his legs. Seeing the condition of the king, Sarah said, ‘O Allah! If he should die, the people will say that I have killed him.’ The king regained his power, and proceeded towards her but she got up again and performed ablution, prayed and said, ‘O Allah! If I have believed in You and Your Apostle and have kept my private parts safe from all except my husband, then please do not let this pagan overpower me.’ The king again fell in a mood of agitation and started moving his legs. On seeing that state of the king, Sarah said, ‘O Allah! If he should die, the people will say that I have killed him.’ The king got either two or three attacks, and after recovering from the last attack he said, ‘By Allah! You have sent a satan to me. Take her to Abraham and give her Ajar.’ So she came back to Abraham (`alayhissalaam) and said, ‘Allah humiliated the pagan and gave us a slave-girl for service.”
Ibn Kathir mentions a hadith about this incident in his book “Stories of the Prophets“. Here is the relevant part of it to help you understand the story better:
Abu Hurairah narrated that Abraham (peace be upon him) did not tell a lie except on three occasions, twice for the sake of Allah, Exalted and Almighty.
The first time was when he said: “I am sick.” When his people were holding a festival in honor of their gods, Abraham excused himself by saying he was sick.
The second time was when he said: “I have not done this but the big idol has done it.”
The third was while Abraham and Sarah, his wife, were going on a journey. They passed by the territory of a tyrant. Someone said to the tyrant: “This man (Abraham) is accompanied by a very charming lady.”
So the tyrant sent for Abraham and asked him about Sarah asking, “Who is this lady?” Abraham said: “She is my sister.” Abraham went to Sarah said “O Sarah! There are no believers on the surface of the earth except you and me. This man asked me about you and I have told him that you are my sister. Do not contradict my statement.” The tyrant then called Sarah.
When she went to him, he tried to take a hold of her with his hand, but his hand got stiff and he was confounded. He asked Sarah: “Pray to Allah for me and I shall not harm you.” Then, Sarah asked Allah to cure him and he got cured.
He tried to take hold of her for the second time, but his hand got as stiff as — or stiffer — than before, and he was once more confounded.
He again requested Sarah: “Pray to Allah for me, and I will not harm you.” Sarah asked Allah again to cure him, and he became all right. He then called one of his guards who had brought her and said: “You have not brought me a human being but have brought me a devil.” The tyrant then gave Hajar as a maid servant to Sarah.
Abraham, gesturing with his hand, asked: “What has happened?” She replied: “Allah has spoiled the evil plot of the infidel or immoral person and gave me Hajar for service.
These “lies” were, in fact, not lies at all. They were merely allusions and ambiguous statements.
When he said to his idolatrous people: “I am sick” [Sûrah al-Sâffât: 87], he intended to insult their idols, of which he was sickened, and to support Allah’s religion. He wanted to show them the falsehood of their idolatry.
When Abraham destroyed the idols of his people, he left the largest idol standing. When his people confronted him and accused him, he said: “Nay! It was done by this largest one of them.” [Sûrah al-Anbiyâ’: 63] By this, he intended to show them clearly that their idols could not actually talk or act or help themselves in any way, and that they were the same as any other pile of rocks. He was forcing them, in this way, to admit that their idols were helpless.
As for his saying to his wife: “Tell him that you are my sister”, we have already seen how he was referring to her being his sister in faith.
Read more on this here. (While I link the post here for the benefit of further reading, I do not recommend its author nor trust his opinions regarding hadith and its legislative position in general.)