I can assure that Y-DNA testing works quite well. These are the possibilities:
(1) Bad genealogy. This is quite common, since many published genealogies do not meet current proof standards.
(2) Non-paternal event (NPE). An NPE occurs when a child does not assume the surname of his/her biological father. This may be due to an out-of-wedlock birth, a formal or informal adoption, a widow's remarrying while pregnant, name change, etc.
(3) Sample switch. While this is always possible, it is extremely unlikely to occur at the lab that Ancestry uses. It adopted bar-coding very early Some were reported earlier at another lab. However, since they adopted bar-coding, I have not heard of any cases.
You need to test other members of the family to see if there is a pattern. If an NPE occurred, you may be able to pin down the generation when it occurred by testing different branches.