Solution:
The answer is 27.
Let us begin with some basic observations. There cannot be only Knights at the table, because they would all have to be mistaken and not just 3 of them. If we look at a Knave or, equivalently, a Knight who is mistaken, next to him sit either two Knaves or two Knights.
Since there is at least one Knave and at least one Knight (actually at least three), there is at least one Knave sitting next to a Knight. In particular the Knaves (assuming there is more than one) cannot sit next to each other, since those "inside" the group could lie, but those on the edge would have a Knave neighbor and a Knight neighbor, which is absurd. Thus the Knaves sit isolated, surrounded by Knights.
Basically, without the Knights who are mistaken, we would then have a sequence of triples of the form CFC.
Let us now bring into play the Knights who are mistaken. They can insert themselves between two Knights (for example between two consecutive triples, but not only there, if there are several in a row) or between two Knaves, that is "eliminating" a Knight, when we look at two consecutive triples: CFCCFC can be replaced by CFCˉFC, where Cˉ is the Knight who is mistaken. In the first case the number of people at the table increases by 1, in the second it decreases by 1 (two Knights are "transformed" into a single Knight).
Let us say there are a mistaken Knights of the first type, that is, sitting between Knights, and 3−a of the second, that is, between two Knaves. Then at the table there are 40=k⋅3+a−(3−a)=3⋅(k−1)+2a, with 0≤a≤3. Since 40 has residue class 1 modulo 3, 2a has residue class 1 modulo 3, hence a=2. This means that we have two mistaken Knights surrounded by Knights and one surrounded by Knaves.
Before considering the mistaken Knights, we had 39 people sitting around the table, of whom 26 were Knights and 13 were Knaves. We added two Knights (who are mistaken) sitting between other Knights, bringing the total number of Knights to 28, after which the third mistaken Knight took the place of two Knights sitting next to each other and surrounded by Knaves, which reduced the total number of Knights to 27.