The unexpected hanging paradox can be found all over the internet. Thus writing it here again would be redundant. I will directly go for solution.

The prisoner says "they cannot hang me on friday because if I am still alive on Thursday I would know that I will be hanged on Friday. Thus it wouldn't be a surprise". This is the starting point of the prisoner. At this point the prisoner is wrong and here is why.

If prisoner concluded that it cannot happen on Friday then if hanging happens on friday the prisoner is still surprised. Prisoner says ".... thus it cannot happen on friday". CANNOT HAPPEN ON FRIDAY.

The important point in this paradox is that prisoner assumes that the Judge takes prisoner's logic into consideration. Prisoner says "it cannot happen on Thursday too. Because judge would know that if I am still alive on Wednesday night and it cannot happen on friday night then I would be sure that I will be hanged on Thursday".

Well, when you say it cannot happen on Friday it was wrong. Thus the second conclusion based ın the first one is also wrong. Why? Because judge will know that you would assume it cannot happen on Thursday and if he hangs you on Thursday you are still surprised. By the time you say it "cannot happen on x day" makes that day a surprising day. Thus making another assumption on a previous false assumption is automatically false.