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, sallallaahu ʻalayhi wa sallam, is His slave and Messenger.
What is prescribed in the Shariah is to carry the body of the deceased on the shoulders to the grave. As for carrying them on a vehicle to the grave, it is contrary to what the Shariah prescribed. However, there is no harm in it if there is a need for that, as is the case when the graveyard is far or the like.
Kashshaaf Al-Qinaa’ reads, “There is no harm in carrying the funeral on the back of a riding animal for a valid reason such as when the grave is far or when the deceased is too heavy (to be carried on the shoulders).”
Ibn ʻUthaymeen was asked, “Which is better, carrying the funeral on the shoulders or on a car?”
He replied, “It is better to carry it on the shoulders, as this is direct carrying. Also, when the funeral passes by the people in the markets, they know that it is a funeral and supplicate Allah in favor of the deceased. Moreover, it is more modest and farther from the blameworthy arrogance and luxury. However, there is no harm in carrying it on a car if there is a need or necessity, such as at times of intense rain, extreme heat, extreme cold, or the scarcity of the mourners.”
He also said, “It is wrong to carry the deceased on a car unless there is a need for it, such as the scarcity of the mourners or extreme cold or heat or rain; otherwise, carrying it on the shoulders is the Sunnah so that the mourners would benefit. Also, it is a good opportunity for the people to derive lessons from the funeral as the mourners pass by them. Moreover, the dead body should be carried on the shoulders to be different from weddings and celebrations. But if there is a need, there is no harm (in carrying it on a vehicle).”
In brief, it is not prohibited to carry the deceased's body to the graveyard on a vehicle; however, it is contrary to the better manner. As for transporting the body to the masjid by car, the basic principle is that it is also permissible.
Allah knows best.