For a dharmic cause can one align with a known unrighteous person if the latter happens to be in favor of this particular cause. Please note that in general the unrighteous person goes against dharma but for this cause the person is on-board. However his underlying motivations are unknown and neither does one know if for the unrighteous person achieving this cause will be an intermediate victory for a different cause he/she is pursuing.
In the Uddhava Gita XVI.19-20 (Swami Madhavananda translator), Sri Krishna says:
By ascribing worth to sense-objects a man comes to be attached to them; from attachment arises the desire for them; from attachment arises the desire for them, and desire leads to dispute among men.
Dispute engenders vehement anger, which is followed by infatuation. Infatuation quickly overcomes his hitherto abiding consciousness of right and wrong.
These preceding verses echo the Bhagavad Gita verses II.62-63.
and in Uddhava Gita XXI.3, Sri Krishna says:
One should never associate with evil persons, who are solely after satisfaction of their animal instincts. One who follows a single one of them falls into abysmal darkness, like a blind follower of the blind.
During Samudra Manthan, Bhagavan Vishnu gives the analogy of a snake, rat & hunter, to Devas when discussing whether to shake hands with Asuras temporarily.
When a snake gets caught in a hunter's net, it asks it's janma-virodhi (rat) for help to gnaw away the net, assuring it of future safety. When rat gnaws off the net, the snake escapes then pounces on the rat.
There is a similar story from the rat's perspective. Where a cat gets caught in a net, and there is a owl on the tree waiting to eat the rat. The rat makes friends with the cat, asking for protection both from the owl (cat's enemy) and the cat itself. The cat agrees. But the smart rat doesn't gnaw off the entire net, for fear the cat would break its promise. Only when the hunter arrives, it gnaws off the final loop of rope, giving the cat just enough time to escape the hunter, and the rat just enough time to escape into a hole.
Heard this in upanyasam, don't have online textual source.