There is no such thing in the Quran as farewell sex with dead wife.
However, as always, you will find anything you want in the hadith books. The enemies of Prophet, as stated in the Quran, were heavily engaged in writing all the bad stuffs and attributed them to the Prophet. They added some good stuffs with bad stuffs and created hadith books, so that no one can understand the satanic trics!
[6:112] We have permitted the enemies of every prophet - human and jinn devils - to inspire in each other fancy words, in order to deceive. Had your Lord willed, they would not have done it. You shall disregard them and their fabrications.
There is a hadith that exists in Kanz al-‘Umal by Mutaqi al-Hindi andAl-Hujja fi Biyan al-Mahujja, an authoritative text on Sunni Doctrine, by Abu Qassim al-Asbahani.
According to this hadith, Muhammad took off his shirt and placed it on a dead woman and “lay” with her in the grave. The buriers proceeded to bury the corpse and the prophet with dirt, exclaiming, “O Prophet, we see you do a thing you never did with anyone else,” to which Muhammad responded: “I have dressed her in my shirt so that she may be dressed in heavenly robes, and I have laid with her in her grave so that the pressures of the grave [also known as Islam’s (false, non-existent) “torments of the grave”] may be alleviated from her.”
Thank you and may God guide me,