We had to do similarly for one of our cats. Grab the cat. Bend the head up. It will practically force the mouth open. Shove the pill deep into it. Close the mouth.
At least, at some point she learned to give up and stop resisting so damn hard every time.
It really depends on the cat's personality. I had one that absolutely hated taking medicines and she behaved in the same way. Others will just gladly take the pill if you hide it in a treat.
I guess I hit the lottery with my cat. She is so sweet and just puts up with me doing what I need to do. When it comes to ear cleaning, she just runs and hides(understandable! I would, too).