Cardiff and Vale University Health Board confirmed it had shut the mental health wards to prevent further spread of the virus.
The health board said a number of cases had been confirmed in the community, including in care homes.
Dr Tom Porter urged anyone eligible to get a free flu vaccine to reduce risk.
He said: "Every year flu causes thousands of deaths across the UK and vaccination is a quick and effective way of reducing your risk."
The dominant strain circulating in the community is influenza A (H3), which particularly affects the elderly.

Mayor Stephanie Rawlings-Blake said she was replacing Police Commissioner Anthony Batts with his deputy, Kevin Davis, for an interim period.
The city was rocked by riots in April when a black man died after suffering injuries in police custody.
Six officers were charged over the death of the 25-year-old, Freddie Gray.
Speaking at a news conference on Wednesday, Mayor Rawlings-Blake said Mr Batts had "served this city with distinction" since becoming police chief in October 2012.
But referring to the city's high homicide rate, she said "too many continue to die".
"The focus has been too much on the leadership of the department and not enough on the crime fighting," she told reporters, adding: "We need to get the crime surge under control."
The city has seen a sharp increase in violence since Freddie Gray's death on 19 April, with 155 homicides this year, a 48% increase over the same period last year.
On Tuesday, the police department announced that an outside organisation will review its response to the civil unrest that followed Mr Gray's death.
The US justice department is also conducting a civil rights review of the Baltimore force and Mr Batts has been criticised by the city's police union.
Earlier on Wednesday, the union released its report into the police handling of the rioting.
It said officers had complained "that they lacked basic riot equipment, training, and, as events unfolded, direction from leadership".
The report also said "officers repeatedly expressed concern that the passive response to the civil unrest had allowed the disorder to grow into full scale rioting".
Recent events had "placed attention on police leadership", Ms Rawlings-Blake said, but denied her decision was influenced by the union report.
Mr Davis, who is taking over immediately as interim police chief, praised his "friend" Mr Batts and said he was a "true reform commissioner".
Mayor Rawlings-Blake said Mr Davis would "bring accountability to police, hold officers who act out of line accountable for their actions".

More than 260 children had been left at the welfare home in Guangzhou since 28 January, director Xu Jiu added.
Staff will continue caring for babies already at the welfare home, all of whom suffer from illnesses, Mr Xu said.
China introduced the centres so parents could abandon infants safely rather than leaving them in the streets.
Supporters say the baby hatches save lives, but critics say they encourage parents to abandon their children.
Mr Xu announced the suspension on Sunday, saying that 262 babies had been left at the centre since the scheme began in January.
"I hope everyone understands the difficulties the welfare centre faces," Mr Xu told Xinhua news agency.
"We are temporarily closing the centre [to new babies] so that we can properly care for the infants already at the centre."
The centre, which also cares for orphans, has 1,000 beds.
However, it currently houses 1,121 babies and young people, with another 1,274 in the care of foster families, Guangzhou's Municipal Civil Affairs Bureau said.
All the abandoned infants had illnesses, such as cerebral palsy, Down's syndrome and congenital heart disease, the bureau added.
It is thought that many parents abandon ill babies because they fear they cannot afford the medical care required.
Abandoning children is illegal in China. However, authorities believe that the hatches give the infants a better chance of survival than if they were left in the street.
A total of 25 baby hatches have been established in 10 provincial regions in China, Xinhua reports.
Under China's strict population control policies, most couples have only been allowed to have one child and there is a strong preference for healthy baby boys.
In December, China's top legislature formally adopted a resolution easing the one-child policy, allowing couples to have two children if either parent is an only child.
Provinces are now determining when to relax their restrictions at a local level, with some acting already.
Three wards treating elderly patients have been closed at Llandough hospital in the Vale of Glamorgan after an outbreak of flu.
[NEXT_CONCEPT]
Baltimore's mayor has sacked the US city's police chief, saying his leadership had become a distraction from fighting a "crime surge".
[NEXT_CONCEPT]
A baby hatch in southern China has been forced to suspend work after hundreds of infants were abandoned, overwhelming the centre, its director says.