The judges were surprised and gave him good marks for John's project.
You can say this. However, the use of the pronoun 'him' ahead of 'John' suggests that 'him' refers to a person who is not John. In other words, it sounds like you mean something like this. The judges were surprised and gave Fred good marks for John's project.