It appears in Bukhaari Shareef  that a sahaabi by the name of Nu`maan bin Basheer radiallahu anhu had presented a slave to his son. His wife insisted that she would only be pleased with him until Nabi salallahu alayhi wasallam approved of him presenting the slave to his son.
This sahaabi went up to Nabi salallahu alayhi wasallam and related what had transpired between him and his wife. He then requested Nabi salallahu alayhi wasallam to approve of his gift to his son.
Nabi salallahu alayhi wasallam asked him, “Have you granted an equal amount to your other children?” He replied in the negative. Nabi salallahu alayhi wasallam then mentioned to him, “Fear Allah Ta`ala and implement equality amongst your children.”
A similar narration appears in Bukhaari Shareef as well, wherein Nabi salallahu alayhi wasallam stated, “Do not appoint me as a witness over your oppression.”
In yet another Hadeeth, Nabi salallahu alayhi wasallam is reported to have mentioned, “I will not stand as a witness over oppression.”
From this we understand that one should be impartial among his children. It is incorrect that one child is granted a gift and the other is either deprived or granted lesser. This is not the estate of a deceased person where each heir is allotted a different share.
(This humble compiler adds that it is stated in the commentary of Muslim Shareef written by Allamah Nawawi rahimahullah
that one should gift an equal amount to each one of his children whether male or female.)
Showing preferential treatment when gifting one’s children is regarded as haraam according to Imaam Ahmad bin Hambal rahimahullah
However, according to Imaam Maalik, Imaam Shaafi`ee and Imaam Abu Hanifah rahimahullah
, it is makrooh to do so and not haraam, and the gift would be approved in shari`ah. The reason for this is that it is reported in a hadeeth that Nabi salallahu alayhi wasallam had told this sahaabi, “Appoint someone else as a witness over your gifting.”
Had it been haraam, Nabi salallahu alayhi wasallam would not have asked him to appoint someone else as a witness over his gifting. As far as the hadeeth wherein Nabi salallahu alayhi wasallam stated: “I will not stand as a witness over injustice,” is concerned, then the explanation for it is, that the meaning of injustice is to move away from the path of equality and justice.
Another point is that everything that falls beyond the definition of equality and justice will either be haraam or makrooh, and in this case the injustice was in the rank of makrooh as is understood from Nabi’s salallahu alayhi wasallam statement:
أَشْهِدْ عَلَى هَذَا غَيْرِي
(appoint someone else as a witness over this.)
The reason for Nabi salallahu alayhi wasallam considering this gifting to be makrooh was that this sahaabi had not gifted to his other children.
In Faidh-ul-Baari, the commentary of Bukhaari, it appears that this sahaabi had two wives with offspring from both. Therefore, it was definitely unjust that he gifts the child of one wife and deprives the children of the other wife. That is why Nabi salallahu alayhi wasallam refused to be a witness to it.
Furthermore, it is written that if showing preference was due to a valid reason then it will not be considered as injustice. For example, one child is pious and the other is a sinner (or one is able to see to his personal needs and the other is unable to do so, or one has a larger family than the other).
أما إذا كان الترجيحُ لداعيةٍ نحو كَوْن أحدِهما مؤمنًا تقيًا، والآخر فاسِقًا شقيًا، فلا جَوْر في التفضيل
Above excerpt is taken from al-malfuzaat by Mufti Mahmood Gangohi rahimahullah, while a similar fatwa appears in his Fatawaa Mahmoodiya as well.
 صحيح البخاري (3/ 158)
2587 – حَدَّثَنَا حَامِدُ بْنُ عُمَرَ، حَدَّثَنَا أَبُو عَوَانَةَ، عَنْ حُصَيْنٍ، عَنْ عَامِرٍ، قَالَ: سَمِعْتُ النُّعْمَانَ بْنَ بَشِيرٍ رَضِيَ اللَّهُ عَنْهُمَا، وَهُوَ عَلَى المِنْبَرِ يَقُولُ: أَعْطَانِي أَبِي عَطِيَّةً، فَقَالَتْ عَمْرَةُ بِنْتُ رَوَاحَةَ: لاَ أَرْضَى حَتَّى تُشْهِدَ رَسُولَ اللَّهِ صَلَّى اللهُ عَلَيْهِ وَسَلَّمَ، فَأَتَى رَسُولَ اللَّهِ صَلَّى اللهُ عَلَيْهِ وَسَلَّمَ، فَقَالَ: إِنِّي أَعْطَيْتُ ابْنِي مِنْ عَمْرَةَ بِنْتِ رَوَاحَةَ عَطِيَّةً، فَأَمَرَتْنِي أَنْ أُشْهِدَكَ يَا رَسُولَ اللَّهِ، قَالَ: «أَعْطَيْتَ سَائِرَ وَلَدِكَ مِثْلَ هَذَا؟»، قَالَ: لاَ، قَالَ: «فَاتَّقُوا اللَّهَ وَاعْدِلُوا بَيْنَ أَوْلاَدِكُمْ»، قَالَ: فَرَجَعَ فَرَدَّ عَطِيَّتَهُ
 شرح النووي على مسلم (11/ 67)
وَفِي هَذَا الْحَدِيثِ أَنَّ هِبَةَ بَعْضِ الْأَوْلَادِ دُونَ بَعْضٍ صَحِيحَةٌ وَأَنَّهُ إِنْ لَمْ يَهَبِ الْبَاقِينَ مِثْلَ هَذَا اسْتُحِبَّ رَدُّ الْأَوَّلِ قَالَ أَصْحَابُنَا يُسْتَحَبُّ أَنْ يَهَبَ الْبَاقِينَ مِثْلَ الْأَوَّلِ فَإِنْ لَمْ يَفْعَلِ اسْتُحِبَّ رَدُّ الْأَوَّلِ وَلَا يَجِبُ وَفِيهِ جَوَازُ رُجُوعِ الْوَالِدِ فِي هِبَتِهِ لِلْوَلَدِ
 فيض الباري على صحيح البخاري (4/ 49)
قوله: (لا أشهد على الجور) وههنا قرينةٌ على كونِه جَوْرًا، لأنه كانت له زَوْجتان، وكان له أولادٌ من كلِّ منهما، ولا رَيْب أن في الترجيح بين أولادِ إحدى الزوجتين مظنة الجَوْر، فأنكر عليه لهذا.