Habaniya is 85km west of Baghdad in the restive province of Anbar, where US forces are battling a fierce Sunni Arab insurgency.
The imam of the mosque had reportedly spoken out against Sunni groups which are fighting the US-backed government, including the group al-Qaida in Iraq.
The bombing is one of the largest to target Iraq's Sunnis in recent months.
Sunni Arabs in Iraq have usually been targeted by Shia death squads while Shias are usually targeted by Sunnis who set off carbombs in civilian districts.
On Monday, two suicide bombers in nearby Ramadi killed 11 people when they targeted the house of Sattar al-Buzayi, a Sunni tribal leader who has campaigned against al Qaeda drive.
Al-Buzayi is backed by the Shia-led government in Baghdad and the US military.