Is he an introverted person, shy or a guy that has a hard time asking girls out? He doesn't know you have a crush on him and he may have a crush on you but is worried that you may reject him since you are just friends. He doesn't want to lose your friendship because he likes you.
Or...
He really does view you as a friend and has an attention seeking flirty nature and those physical gestures really mean nothing beyond wanting a little attention from you in the moment.
EDIT: shit, this is ask the gals... Seemed like a question for the guys... my bad.
If he's outright told you that he's not into you, then he's not into you.
Maybe he enjoys playing with you this way because he knows he can. Some guys are really touchy-feely, so maybe he feels comfortable enough being so hands-on with you because he knows you'll allow it. I know this makes it extra confusing for you because you're into him. In some cases, some of us make the mistake of reading too much into every single gesture because we want that spark to be there. However, this isn't the issue in your case.
If you're into him and he's admittedly not into you, the best thing you can do is distance yourself from him or set some boundaries and take some time to let these feelings subside. The last thing you need is to play cuddly, tickly, top-of-the-head kissy games with a guy you're into but has repeatedly told you that he's not into you.
And I have to ask, does he know you're into him? Because if he does, then he's just being really cruel.
Also, he may not be into you relationshipwise, but perhaps he's physically attracted to you...and may be interested in having sex with you. If you're into that, you may very well have yourself a fuck buddy.
░P░U░S░S░Y░ ░I░N░ ░B░I░O░