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 detested 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 rested on his shoulder. They soon made out and were about to have sex until Charlie and Jake arrived at home, interrupting the encounter. 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.
When she and Herb have marital problems in It's Always Nazi Week, Alan is pleased at her second failed marriage and went to see her house to gloat. After she broke down, he comforted her while he secretly took pleasure in her sadness but said she was still attractive for her age, as she was surprised at this. Judith then kissed him intently, which surprised him though he returned it before they have an affair by having sex which she enjoys.