In The Name of Allaah, The Most Merciful, The Bestower of Mercy
Allaah (The Most High) said:
يَـٰٓأَيُّہَا ٱلَّذِينَ ءَامَنُواْ كُونُواْ قَوَّٲمِينَ بِٱلۡقِسۡطِ شُہَدَآءَ لِلَّهِ وَلَوۡ عَلَىٰٓ أَنفُسِكُمۡ أَوِ ٱلۡوَٲلِدَيۡنِ وَٱلۡأَقۡرَبِينَۚ إِن يَكُنۡ غَنِيًّا أَوۡ فَقِيرً۬ا فَٱللَّهُ أَوۡلَىٰ بِہِمَاۖ فَلَا تَتَّبِعُواْ ٱلۡهَوَىٰٓ أَن تَعۡدِلُواْۚ وَإِن تَلۡوُ ۥۤاْ أَوۡ تُعۡرِضُواْ فَإِنَّ ٱللَّهَ كَانَ بِمَا تَعۡمَلُونَ خَبِيرً۬ا
O you who believe! Stand out firmly for justice, as witnesses to Allah; even though it be against yourselves, or your parents, or your kin, be he rich or poor, Allah is a Better Protector to both (than you). So follow not the lusts (of your hearts), lest you may avoid justice, and if you distort your witness or refuse to give it, verily, Allah is Ever Well-Acquainted with what you do. [Surah An-Nisaa’ Ayah 135]
Imaam Ibnul Qayyim [rahimahullaah] said:
Allaah [Glorified be He and Free is He From all Imperfections] command His [servants] to stand out firmly for justice on behalf of everyone – whether an enemy or an ally. And the affair that is most worthy of being established with justice -by a person- are the [sound and upright] statements, views and methodology related to the commands of Allaah and everything else Allaah has informed [His slaves in the Qur’aan and the Sunnah]. Therefore, to establish these affairs based on desires and disobedience is something contrary to the command of Allaah and a negation of what Allaah’s Messenger [sallal-laahu-alayhi-wasallam] was sent with [i.e. the Qur’aan and the Sunnah].
The establishment of justice [based on what Allaah and His Messenger have commanded] is the responsibility of those entrusted with the task to convey Islaam after the death of the Messenger [sallal-laahu-alayhi-wasallam], and this task cannot become a reality unless when one establishes it based on pure justice and sincerity to Allaah; [sincerity] to Allaah’s Book; [sincerity] to Allaah’s Messenger and out of sincere advice to Allaah’s servants. These [people] are the true inheritors [of the knowledge left behind by the Prophets]. [A true inheritor of the Prophet [i.e. a righteous scholar] is not that one who merely makes his companions, sect and school of thought the determinants of truth and the distinction between [truth and falsehood] -by showing enmity towards the one who opposes him and allies with the one who agrees with him, merely based on being opposed or agreed with, [without sound proofs based on the Book and the Sunnah]- for where is that [application of the] command to stand out firmly for justice on behalf of everyone [in the actions of that person who merely opposes or agrees with others based on other than the sound proofs found in the Qu’aan and the authentic Sunnah], even though standing out firmly for justice [based on the sound proofs in the Qur’aan and the authentic Sunnah] is the greatest command and obligation?!
Then Allaah (The Most High) says: [شُہَدَآءَ لِلَّهِ – As witnesses to Allah]: A witness is that one who presents information about something; therefore if he presents credible information, he is [considered to be] a just witness and his [statement] is accepted; but if he gives false information, he is [considered] a false witness. Allaah [The Most High] command [us] to stand out firmly as just witnesses for His sake, therefore it has to be carried out for the Sake of Allaah and not for other than Allaah.
And in [Surah Al-Maa’idah Ayah 8, Allaah (The Most High) said]: [كُونُواْ قَوَّٲمِينَ لِلَّهِ شُہَدَآءَ بِٱلۡقِسۡطِۖ – Stand out firmly for Allah and be just witnesses]: This Aayah establishes four affairs:  One should stand out firmly for justice and  does so for the sake of Allaah; Witness to justice and  does so for the Sake of Allaah.
Then Allaah [The Most High) said: [وَلَوۡ عَلَىٰٓ أَنفُسِكُمۡ أَوِ ٱلۡوَٲلِدَيۡنِ وَٱلۡأَقۡرَبِينَۚ – Even though it be against yourselves, or your parents, or your kin];
Allaah [Glorified Be He and Free is He from all imperfections] commands [us] to stand out firmly for justice and testify [for or against] everyone, even if it were [against] someone who is the most beloved to person to [us]. A person should stand out firmly for justice [whether it is for or against] himself, his two parents, his other close relatives and his best friend amongst the people. If the person’s love for himself, his parents and his relatives prevents him from standing out firmly for the truth against them, especially if the truth is with someone he hates and regards as an enemy due to them, then indeed none will stand out firmly for justice in such circumstances except one whose love for Allaah and His Messenger is more than their love for everyone else. This is a test of one’s Eemaan, so that he becomes acquainted with the level of Eemaan [in relation to this affair] and [its importance] in his heart.
On the other hand a person has to establish justice when dealing with his enemies and [even] that one who deprives him of his rights; for indeed it not permissible that hatred for his enemies leads him to be unjust towards them, just as it is not permissible [to allow] love of himself, his parents and relatives to make him abandon standing firmly for justice against them. Therefore, hatred harboured against someone should not lead him to falsehood and love [of himself, parents and relatives] should not make him fall short in establishing truth, just as some of the Salaf said: ‘’The just person is that one who when angry, his anger does not lead him to falsehood, and when he is pleased, it does not remove him from truth.” The two verses of the Qur’aan [i.e. 4:135 & 5:8] convey two rulings and they are: Standing out firmly for justice and making a truthful testimony to it- on behalf of one’s allies and enemies.
Then Allaah [The Most High] said: [إِن يَكُنۡ غَنِيًّا أَوۡ فَقِيرً۬ا فَٱللَّهُ أَوۡلَىٰ بِہِمَاۖ – Be he rich or poor, Allah is a Better Protector to both (than you)]- Meaning: Allaah is the Lord of both of them and Allaah is their Protector, and they are both His slaves. It may be that you become fearful of standing firmly for justice by testifying against a rich person or a poor person – either fearing that the rich person might lose his wealth or because the poor person has nothing, so your hearts become lackadaisical towards standing out firmly for the truth. Therefore, it should be said to them [i.e. the people]: Allah is a Better Protector to both the rich and poor person [than you]. Allaah knows the affair of the rich person more than you and He is more Merciful to the poor than you, so do not refrain from standing out firmly for the truth and from giving testimony [for or against] the rich or the poor.
Then Allaah said: [فَلَا تَتَّبِعُواْ ٱلۡهَوَىٰٓ أَن تَعۡدِلُواْۚ – So follow not the lusts (of your hearts), lest you may avoid justice]-Meaning: Allaah forbids [His slaves] from following desires, which will lead them to abandon justice. Then Allaah [The Most High] said:
[وَإِن تَلۡوُ ۥۤاْ أَوۡ تُعۡرِضُواْ فَإِنَّ ٱللَّهَ كَانَ بِمَا تَعۡمَلُونَ خَبِيرً۬ا – and if you distort your witness or refuse to give it, verily, Allah is Ever Well-Acquainted with what you do]- Meaning: Allaah [Glorified Be He and Free is He from all imperfections] mentions two reasons that will inevitably lead to concealment of truth, then He warned against them and threatened [the one who perpetrates this sin]. The first of them is distortion and the second is to turn away from giving truthful witness. That is because when a proof that supports the truth is manifested and the one who wants to repel it finds no way of doing so, he refrains from mentioning it and thus becomes a silent devil, and sometimes he distorts it. Distortion is of two types: Distortion in wording and distortion in meanings. Distortion in wording is when one utters a word in a context in which it does not establish the truth – either adding to the word or omitting something from it, or substituting it with something else- to the extent that the listener is made to believe something, whilst something else is intended by it, just as the Yahood [i.e. those Yahood who disbelieved in the Prophet & hated him] used to distort words when giving Salaam to the Prophet [i.e. saying As-Saamu Alayka (death be upon you), instead of saying Assalaamu alaykum). This is one type of distortion.
The second type of distortion is related to meanings – distorting the wording; giving it an interpretation that is not intended by the one who uttered it and pretending not to know what is not its intended meaning, or dropping other meanings intended by it etc. Allaah [The Most High] said:
[وَإِن تَلۡوُ ۥۤاْ أَوۡ تُعۡرِضُواْ فَإِنَّ ٱللَّهَ كَانَ بِمَا تَعۡمَلُونَ خَبِيرً۬ا – and if you distort your witness or refuse to give it, verily, Allah is Ever Well-Acquainted with what you do].
And when it is the case that a witness is required to bear witness based on what the affair should be [i.e. the complete truth], therefore neither should he hide nor change it. Turning away from the testimony is tantamount to concealment and distortion is tantamount to alteration and substitution. Therefore, contemplate on this ayah and the treasures of knowledge it contains. The Eemaan of a person cannot be complete, except by way of accepting the texts of the sharee’ah and calling the people to them – neither turning away from them at times nor distorting them at other times.
[Source: Badaa’i At-Tafseer Al-Jaami Limaa Fassarahu Al-Imaam Ibnul Qayyim (rahimahullaah). Vol 1. Page 300-303. Abridged & slightly paraphrased]