Sayyiduna Ali (may Allah be pleased with him) said: "The imam is the most entitled to lead the prayer over any funeral."