The solution to this puzzle is somewhat paradoxical. The prisoner may reason like this:

Days of week are: First Sunday (the day judge came to prison), Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Second Sunday.

Assumption: The judge told the truth.

Assumption: They want him executed on the second Sunday.

That means they don't want him executed on any other day of week, and no one told him on the first Sunday: "You're going to be executed tomorrow", nor on Monday, Tuesday, and so on until Friday. So after Friday's dinner, he knew he wouldn't be executed on Saturday (he didn't "get to know" it during dinner) or on any other day of this week, because they have passed. That leaves only the second Sunday, and so exacly after Friday's dinner he "got to know" the day they wanted him executed. This contradicts "you will get to know the day we want you executed during the dinner the day before it", because he got to know it earlier.

That means the assumption is wrong, and there is no way they want him executed on the second Sunday.

Assumption: They want him executed on Saturday.

Since the prisoner has established that he cannot be executed on the second Sunday, the same argument follows. After Thursday's dinner, he knew he wouldn't be executed on Friday, and so he can only be executed on Saturday, again contradicting "you will get to know the day we want you executed during the dinner the day before it".

That means the assumption is wrong, and there is no way they want him executed on Saturday.

The argument can be applied to each day of the week in turn, and so there is no day of the week on which they can have decided to execute him, contradicting "We have already decided the day".

That means the assumption is wrong, and what judge said is false.

However, this whole argument is false. While it may seem as though the judge cannot be telling the truth, it is in fact impossible to infer from what the judge has said. To understand the reason for this, it is important keep the statements "the judge is telling the truth" and "the prisoner knows that the judge is telling the truth" separate.

If the prisoner's argument is sound, then he knows that the judge is lying. Suppose then that one evening the judge tells the prisoner "tomorrow you will be executed, as was decided earlier", and the prisoner is executed the next day. Since the prisoner thought the judge was lying, he did not anticipate this. But that means the judge was actually telling the truth. Thus, the argument cannot have been sound.