The New York Times has a story of several American citizens (as well as a dual U.S./ Spain citizen, but that's clearly a suspicious, Spanish-speaking country) who were detained and then flagged as illegal immigrants, thanks to lousy Department of Homeland Security (DHS) records. One man, who was arrested for apparent accidental shoplifting, was previously deported to Mexico. His DHS file mentioned this, but not the fact that the original deportation was a mistake.
As to why those charged with defending the homeland from terrorists and other harmful thing can't tell the difference between who is a citizen of this country and who isn't, well:
Unlike the federal criminal databases administered by the F.B.I., Homeland Security records include all immigration transactions, not just violations. An immigrant who has always maintained legal status, including those who naturalized to become American citizens, can still trigger a fingerprint match.
According to Margaret Stock, an immigration lawyer in Alaska, under the nation’s complex citizenship laws, many foreign-born people become Americans automatically, through American parents or adoption. Often their citizenship is not recorded in Homeland Security databases, Ms. Stock said.
As to how often this happen to U.S. citizens, the article offers this:
Exact numbers of Americans erroneously held by immigration authorities are hard to come by, since they are not systematically recorded. In one study, 82 people who were held for deportation from 2006 to 2008 at two immigration detention centers in Arizona, for periods as long as a year, were freed after immigration judges determined that they were American citizens.
The rest here.
Reason on the U.S.'s broken immigration system.