Generally, they can file such a lawsuit, but they cannot judge it.
In federal courts, 28 USC 455 applies:
(a) Any justice, judge, or magistrate judge of the United States shall disqualify himself in any proceeding in which his impartiality might reasonably be questioned.
(b) He shall also disqualify himself in the following circumstances:
(5) He or his spouse, or a person within the third degree of relationship to either of them, or the spouse of such a person:
(i) Is a party to the proceeding...
And in federal court, this cannot be waived.
(e) No justice, judge, or magistrate judge shall accept from the parties to the proceeding a waiver of any ground for disqualification enumerated in subsection (b).
State laws vary, of course. For example, under Wisconsin law 757.19:
(2)Any judge shall disqualify himself or herself from any civil or criminal action or proceeding when... a judge is a party or a material witness, except that a judge need not disqualify himself or herself if the judge determines that any pleading purporting to make him or her a party is false, sham or frivolous.
But under Wisconsin law, unlike federal law, this conflict of interest can be waived if everyone agrees:
Any disqualification that may occur under sub. (2) may be waived by agreement of all parties and the judge after full and complete disclosure on the record of the factors creating such disqualification.
This isn't just theoretical, by the way - it does happen sometimes. In West Virginia, the state legislature recently decided to impeach the entire state supreme court. One of the justices filed suit against this, and the court had to appoint substitute judges to hear the case, because they all had to recuse themselves.