After being threatened by Saul, David leaves his wife who subsequently is given to another man. Years later when David becomes king he requests that his wife be given back to him.
2 Samuel 3:14, 15 NIV —
Then David sent messengers to Ish-Bosheth son of Saul, demanding, “Give me my wife Michal, whom I betrothed to myself for the price of a hundred Philistine foreskins.” So Ish-Bosheth gave orders and had her taken away from her husband Paltiel son of Laish.
But according to the law it seems David had made himself detestable and obnoxious to the Lord
Deutoronomy 24:1–4 NIV —
If a man marries a woman who becomes displeasing to him because he finds something indecent about her, and he writes her a certificate of divorce, gives it to her and sends her from his house, and if after she leaves his house she becomes the wife of another man, and her second husband dislikes her and writes her a certificate of divorce, gives it to her and sends her from his house, or if he dies, then her first husband, who divorced her, is not allowed to marry her again after she has been defiled. That would be detestable in the eyes of the Lord.
Again Jeremiah reiterates the same law
Jeremiah 3:1 NIV —
If a man divorces his wife
and she leaves him and marries another man,
should he return to her again?
Would not the land be completely defiled?
Did David not defile himself by taking back Michal?