Their relationship was not very good in general. It is unknown when they started dating but it's known that they separated in the "Pilot" and they officially were divorced in "Twenty-Five Little Pre-Pubers Without A Snoot-ful". She said that they could not continue their relationship because she had become a lesbian, but in "Alan Harper, Frontier Chiropractor" it was confirmed that that was only an excuse to divorce Alan. Judith finally reveals in "A Pot Smoking Monkey" that she always hated Alan, even before they committed (after he went to Judith's house and asked if he could ask for a divorce lawyer for Alan and Kandi. But she said no because she represented her and then Alan asked Judith when she began to hate him so much).
Despite all this, Judith and him also had good times. For example, in the episode "Go Get Mommy's Bra", when she broke up with her boyfriend Greg and Alan went to genuinely comfort her, she accepted his kindness and they made out and were about to have sex until Charlie and Jake arrived at home. It was likely this brought up old feelings, as in "Carpet Burns and a Bite Mark", they began to date again and had sex but after getting into yet another argument with her, Alan decides not to see her anymore.