Riyad as-Salihin, Book 1, Hadith 237 (In-Book)

Anas (May Allah bepleased with him) reported: Messenger of Allah said, "Help your brother, whether he is an oppressor or is oppressed". A man enquired: "O Messenger of Allah! I help him when he is oppressed, but how can I help him when he is an oppressor?" He said, "You can keep him from committing oppression. That will be your help to him".[Al-Bukhari and Muslim].

وعنه قال‏:‏ قال رسول الله صلى الله عليه وسلم‏:‏ “انصر أخاك ظالمًا أو مظلومًا” فقال رجل‏:‏ يا رسول الله أنصره إذا كان مظلومًا أرأيت إن كان ظالمًا كيف أنصره‏؟‏ قال‏:‏ ‏"‏تحجزه -أو تمنعه- من الظلم فإن ذلك نصره” ‏(‏‏(‏رواه البخاري‏)‏‏)‏‏.‏

sunnah.com