A Welsh hospital has had to close two wards due to an outbreak.