All perfect praise be to Allah, The Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad, sallallahu ‘alayhi wa sallam, is His slave and Messenger.
There are many religious texts stating the prohibition of attributing someone to other than their real father or claiming to be the son of any person other than one's real father. Allah, The Exalted, says (what means): {Call them by (the names of) their fathers; it is more just in the sight of Allah.} [Quran 33:5] Abu Tharr, may Allah be pleased with him, reported that he heard the Prophet, sallallahu ‘alayhi wa sallam, say, “If a man knowingly claims to be the son of any other than his real father, he has disbelieved in Allah, and whoever claims to belong to some folk to whom he does not belong, let him take his place in Hellfire.” [Al-Bukhari and Muslim] Sa‘d ibn Abi Waqqaas and Abu Bakrah, may Allah be pleased with them, narrated that the Prophet, sallallahu ‘alayhi wa sallam, said, “If a man claims to be the son of a man who is not his real father, knowing that he is not his real father, then Paradise is forbidden for him.” [Muslim]
There are many ahaadeeth to this effect; they all indicate the prohibition of this act and that the doer is subjected to stern warnings in this regard. All this applies to the case in which these people attribute themselves to their maternal grandfathers in a way that hides the identity of the real father so that people believe that they are actually the grandsons of those famous grandfathers. However, if they only mention that they are the children of those grandfathers in the sense that they are from their descendants without replacing their fathers’ names, then there is no harm in that. indeed, the maternal grandfather is considered a father of his grandchildren.
The Prophet, sallallahu ‘alayhi wa sallam, said about his grandson Al-Hasan, may Allah be pleased with him, “This son of mine is a master.” There is no problem in this regard if their father's name is not hidden or replaced with the name of their grandfather and if they only wish to make their noble lineage known to people. Some scholars were famous due to the fame of their maternal grandfathers.
Shaykh Ibn Baaz wrote:
“The daughter’s sons are called the sons of their maternal grandfather. It has been authentically reported that the Prophet, sallallahu ‘alayhi wa sallam, said about Al-Hasan ibn ‘Ali, ‘This son of mine is a master.’ Al-Hasan was his daughter Fatimah’s son, may Allah be pleased with her and with her sons, Al-Hasan and Al-Husayn. Allah, The Exalted, stated that ‘Eesa (Jesus), the son of Maryam (Mary), was from the descendants of Prophets Nooh (Noah) and Ibraaheem (Abraham); Allah, The Exalted, says (what means): {And We gave to Ibraaheem, Is-haaq (Isaac) and Ya‘qoob (Jacob) - all (of them) We guided. And Nooh, We guided before; and among his descendants, Daawood (David) and Sulaymaan (Solomon) and Ayyoob (Job) and Yoosuf (Joseph) and Moosa (Moses) and Haaroon (Aaron). Thus, do We reward the doers of good. And Zakariyya (Zechariah) and Yahya (John) and ‘Eesa (Jesus) and Elyaas (Elias) - and all were of the righteous.} [Quran 6:84-85] It is well-known that ‘Eesa, may Allah exalt his mention, was born to a mother only and had no father. He was the descendant of Aadam (Adam), Nooh, and Ibraaheem, may Allah exalt their mention.” [Fataawa Ibn Baaz]
Allah knows best.