means that
someone wastes energy opposing an imaginary threat or engaging in a pointless struggle.
Imagine a case where to struggle against imaginary problems, unnecessary fears, or difficulties that exist only in one's own mind.; then “To fight with one’s own shadow” fits well.