All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
If the pension is a gift from the authority that gives it and it is not something that it (the authority) owes to the dead, then it should be given to those who were designated by the authority that gave it and the will of the dead is not taken into account as to where or how it should be spent.
However, if this pension is something which that authority owes to the dead, then it is considered as a part of the inheritance. For more benefit, please refer to Fataawa 90709 and 118722.
So, if the deceased had made a will that this pension be given to his grandson while the latter is not an heir, then he [grandson] is entitled to this will but he should not take from this pension what exceeds a third of the whole inheritance except with the consent of all other heirs among whom is his (the deceased's) wife.
This applies if the grandson is not an heir, as we mentioned before, but if he is an heir, then he is not entitled to receive anything from the pension – even a single penny – except with the consent of all heirs because a will to an heir is not valid except with the consent of all heirs.
For more benefit on a will for an heir, please refer to Fataawa 116588 and 119243.
Allaah Knows best.