Should ceiling fan mounting screws thread into the box or the framing behind?
Screwing into a ceiling joist through holes in the pancake box is a sound method for securing a fan bracket, if the wood screws are rated for the purpose. I have installed Hunter fans that way using the special wood screws supplied with the fan. If this is a new fan, read the instructions and examine the hardware supplied.
The black screws in the OP's pic however do no appear to be rated for holding a fan. If the fan you are installing does not have wood screws for this purpose, then you will have to source some that will work.