2 of my cats are weird. One minute they love you and the next you try and go to pet them and they run away from you. Pepper does it the most. Mimi is usually nice, but when she does that it's really weird.
Why do they do it?
I would guess that it's because they're cats! At least my 5 yr old cat only allows petting when SHE wants it, not when I would like to, so if you try and pet her when she's not in the mood, she'll either go away, or grab your hand and bite down gently. Of course there could always be some other reason, like you having some smell they don't like at that moment (like if you've been peeling oranges or something).
Our 7 month old Sassy does this many times a day. Sometimes she's very into being pet. Then, there are times if you start to extend a hand toward her, she scampers away like you were trying toss her out!