You're looking for the scenarios in which none of the cowboys have their own hats.
Let's assign each cowboy a number (1, 2, 3) and each hat a letter (A, B, C). Now let's say that hat A belongs to cowboy 1, hat B to cowboy 2, and hat 3 to cowboy C, so when each cowboy has his own hat it looks like 1A, 2B, 3C.
Now write out each combination
1A, 2B, 3C (they all have their own hat)
1A, 2C, 3B (Cowboy 1 has his own hat)
1B, 2C, 3A (None of them have their own hat)
1B, 2A, 3C (Cowboy 3 has his own hat)
1C, 2A, 3B (None of them have their own hat)
1C, 2B, 3A (Cowboy 2 has his own hat)
So there are six possible combinations and two where none of them have their own hat, so that's 2/6 which is 1/3.