The attack, which also left 75 people wounded, struck at the Sayid al-Shuhada mosque in Tuz Khurmatu, 175 kilometres (110 miles) north of Baghdad, and targeted the funeral of a relative of a politician who was killed a day earlier.
No group claimed responsibility, but Sunni militants often launch attacks in a bid to destabilise the government and push Iraq back towards the sectarian violence that blighted it from 2005 to 2008.
Niyazi Moamer Oghlu, the secretary general of the provincial council of Salaheddin, which surrounds Tuz Khurmatu, put the toll from the attack at 42 dead and 75 wounded.
"Corpses are on the ground of the Husseiniyah (Shiite mosque)," said Shallal Abdul, mayor of Tuz Khurmatu, which lies 175 kilometres (110 miles) north of Baghdad. "The suicide bomber managed to enter and blow himself up in the middle of the mourners."
Among the wounded were officials and tribal leaders, including Ali Hashem Mukhtar, the deputy chief of the Iraqi Turkman Front and a provincial councillor in Salaheddin, which surrounds Tuz Khurmatu.
The funeral had been for Mukhtar's brother-in-law, who was shot dead in Tuz on Tuesday afternoon.
Wednesday's suicide bomb came after a wave of attacks in and around Baghdad and in northern Iraq killed 26 people and wounded dozens more, shattering a relative calm after a spate of deadly violence last week.
The unrest comes amid a political crisis that has pitted Prime Minister Nuri al-Maliki against several of his erstwhile government partners and with more than four weeks of anti-government protests in Sunni majority areas hardening opposition against the Shiite leader's rule.