Yes, there is an authentic hadeeth that states this.
So, is itikaf only allowed in the three masjids (i.e. Masjid Al-Haraam, Masjid An-Nabawi, and Masjid Al-Aqsa)?
Firstly, here is a treatise which shows that this is an authentic hadeeth: Clarifying the Evidence in Referencing and Verifying the Hadeeth “There is no Itikaf except in the three Masjids” by Shaikh Muhammad Al-Wasaabee.
[It’s a bit hard core.]
Secondly, this is not how most of the scholars understood it. The following article explains the issue:
I heard a hadeeth which says that i’tikaaf is only valid in al-Masjid al-Haraam (in Makkah), al-Masjid al-Nabawi (in Madeenah) and al-Masjid al-Aqsa (in Jerusalem). Is this hadeeth saheeh?
Praise be to Allaah.
The hadeeth to which the questioner is referring was narrated by al-Bayhaqi (4/315) from Hudhayfah, who said to ‘Abd-Allaah ibn Mas’ood (may Allaah be pleased with him): I saw some people who were observing i’tikaaf between your house and the house of Abu Moosa (i.e., in the mosque) and I know that the Messenger of Allaah (peace and blessings of Allaah be upon him) said: “There is no i’tikaaf except in the three mosques: al-Masjid al-Haraam…” ‘Abd-Allaah ibn Mas’ood said: Perhaps you forgot and they remembered, or you made a mistake and they were correct.
This was classed as saheeh by al-Albaani in Silsilat al-Ahaadeeth al-Saheehah (2876). Secondly: With regard to the ruling on this matter, the majority of scholars are of the view that it is not essential for i’tikaaf to be observed in one of the three mosques. They quoted as evidence for that the verse in which Allaah says (interpretation of the meaning): “And do not have sexual relations with them (your wives) while you are in I‘tikaaf (i.e. confining oneself in a mosque for prayers and invocations leaving the worldly activities) in the mosques” [al-Baqarah 2:187] The word masaajid in this verse includes all mosques, except those of which the evidence states that i’tikaaf is not valid therein, such as mosques in which prayers are not held in congregation, if the person who is observing i’tikaaf is one of those on whom prayer in congregation is obligatory. See question no. ( 48985 ) Imam al-Bukhaari referred to the general meaning of the verse. He said: