This is a congruent conflation of “tough cookie” and “a hard (or tough) nut to crack”, both describing difficult people to deal with. I suppose you can crack cookies, particularly if they are very stale. My mom would put a piece of bread in the cookie jar to avoid cracked cookies. A big thanks to Mary for blurting this one out, describing her very sassy cat. Apparently the cat is still a tough cookie to crack.
This is a straightforward malaphor, mixing “that’s the way the cookie crumbles” and “that’s the way the ball bounces”, both meaning you can’t control everything that happens to you. It also could describe the rejects from cookie exchanges this time of year.