What are the cases in which the funeral prayer cannot to be offered for the deceased?
Question

                When a person dies what are the circumstances that they cannot be prayed upon before being inserted into the grave.
Praise be to Allah.
    The funeral prayer is a communal obligation (fard kifaayah) 
    that must be offered for anyone who dies and was apparently Muslim, even if 
    he or she committed major sins. 

    An-Nawawi (may Allah have mercy on him) said: 

    Offering the funeral prayer for the deceased is a communal 
    obligation with no difference of opinion among us, which means there is 
    (scholarly) consensus.

    End quote. al-Majmoo‘, 5/167 

    There is no shar‘i evidence to suggest that there was any 
    exception to offering the funeral prayer for any Muslim except the shaheed 
    (martyr) who was killed in battle. 

    Ibn al-Qayyim (may Allah have mercy on him) said: 

    The funeral prayer is not to be offered for the martyr who 
    was killed in battle, because the Messenger of Allah (blessings and peace of 
    Allah be upon him) did not offer the funeral prayer for the martyrs of Uhud, 
    and it is not known that he offered the funeral prayer for any of those who 
    were martyred fighting alongside him in his campaigns. The same is also true 
    of his successors, the Rightly Guided Caliphs, and their governors and 
    commanders.

    End quote from Zaad al-Ma‘aad, 3/217 

    See also the answer to question no.
    14012 

    With regard to the miscarried foetus, if it had not reached 
    four months’ gestation, no funeral prayer is to be offered for it because it 
    is not regarded as human and the soul had not yet been breathed into it. If 
    it is miscarried after four months of pregnancy, then the funeral prayer is 
    to be offered for it. 

    The scholars of the Standing Committee for Issuing Fatwas 
    said: 

    If the foetus had not reached four months’ gestation, then it 
    is not to be washed and the funeral prayer is not to be offered for it; it 
    is not to be given a name and no ‘aqeeqah is to be offered for it, because 
    the soul had not yet been breathed into it. 

    End quote from Fataawa al-Lajnah ad-Daa’imah, 8/408 

    There are some individuals whose situation is not clear to 
    others, so people think that they are Muslims and offer the funeral prayer 
    for them, when in fact they are not Muslims, such as apostates and 
    hypocrites. 

    Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) said: 

    The apostate of any type is not to be treated in the same 
    manner as one who is originally a kaafir; rather he has to return to Islam. 
    If he becomes Muslim again, all well and good; if he does not become Muslim 
    then he is to be executed as a kaafir. He is not to be buried with the 
    Muslims and the funeral prayer is not to be offered for him. 

    End quote from Fataawa Noor ‘ala ad-Darb, 14/6 

    With regard to the hypocrite, who is the one who conceals 
    kufr whilst outwardly appearing to be Muslim, if it is known that a person 
    is a hypocrite, then the funeral prayer is not to be offered for him. 

    Allah, may He be exalted, says (interpretation of the 
    meaning):

    “And never (O Muhammad SAW) pray (funeral prayer) for any 
    of them (hypocrites) who dies, nor stand at his grave. Certainly they 
    disbelieved in Allah and His Messenger, and died while they were Fasiqoon 
    (rebellious, - disobedient to Allah and His Messenger SAW)”

    [at-Tawbah 9:84]. 

    Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him) 
    said: 

    If it is known that a person is a hypocrite, it is not 
    permissible to offer the funeral prayer for him or pray for forgiveness for 
    him. If no such thing is known about a person, then the funeral prayer 
    should be offered for him. If an individual knows that a person was a 
    hypocrite he should not offer the funeral prayer for him, but those who did 
    not know that he was a hypocrite may offer the funeral prayer for him. 

    ‘Umar (may Allah be pleased with him) used not to offer the 
    funeral prayer for one for whom Hudhayfah did not offer it, because during 
    the campaign to Tabook, he knew who the hypocrites were who planned to kill 
    the Messenger of Allah (blessings and peace of Allah be upon him). End quote 
    from Minhaaj as-Sunnah, 5/160 

    And Allah knows best.