Both sentences are perfectly grammatically correct. There is no grammatical preference for one over the other. That said, the two sentences are semantically different, and their content says two completely different things. The two sentences are NOT interchangeable. You CANNOT substitute one for the other, just as you cannot substitute "I like apples" for "I like oranges". They mean two different things. Likewise, you can't substitute "I wasn't aware there was a party, so I didn't go to the party" for "I was kidnapped and locked in a closet, so I didn't go to the party." All of these sentences are grammatically fine, it's the content that is different.
"If only he knew about the surprise party that is awaiting him."
He doesn't know about the party now, but if he learns about it, something significant will happen... presumably, he will be extremely happy and surprised. I don't want him to learn about it early, but I am eager and excited to see his pleasant reaction at the party's reveal.
"If only he could know about the surprise party that is awaiting him."
He is incapable of learning about the party by any means, but I wish he was able. I am sad that he is unable to obtain this knowledge; maybe he is far away and can't receive communication, or maybe he is sick in the hospital, in a medically induced coma. Whatever his condition, he literally can't know, and I wish he could.