TMZ has learned Justin Timberlake was ordered to show up in court Monday to prove the woman he's accused of harassing him is a threat ... but the judge who made the order had already been removed from the case by Justin's lawyer.
As we first reported, Timberlake obtained a temporary restraining order last month against Karen McNeil. Timberlake claims she showed up at his property several times without invitation.
Timberlake's case is due back in court Monday -- his lawyer will try to make the restraining order permanent.
Timberlake filed a declaration in the case, but the more detailed declarations filed were from his two bodyguards, claiming the woman is an ominous stranger.
McNeil submitted a 60-page response in which she said she's a long time friend of Timberlake's. Although the response is rambling and crazy, it's her word against the bodyguards who don't know Timberlake that well.
As a result, sources tell us Judge Carol Boas Goodson told Timberlake's lawyer to get his client in court on Monday and testify himself about McNeil. But we've learned two days before Judge Goodson made the order, Timberlake's lawyers had already submitted papers to disqualify her from hearing the case.
So bottom line ... Timberlake was ordered to appear by a judge who no long had the case.
We don't know if Timberlake will show on Monday ... stay tuned.