Can I turn down a postdoc offer after I have received the official offer letter but haven't sign it
The appropriate time is after you get the other (better) offer in writing.  You don't want to turn something known down for something else that hasn't come yet, formally.

Yes, it is unfortunate to have said you will take the position and turn it down, but these things happen.  Certainly in business, there are lots of times when agreed to deals still fail when the time comes to put pen to paper.  It is not the end of the world. Just be matter of fact (not penitent, not rebellious) and move forward with whatever is the best fit for you.

P.s.  This is why I emphasize to interview widely and job search arduously, all the way up to having gotten a written offer and accepted it.  You're not off the market until then.  The same thing applies in reverse as verbal offers may not always materialize (check out lots of questions/complaints about this on this site).  I'm not advocating being deceptive or fickle.  But you certainly want to look for your best situation and control the options as much and as long as you can.  Employers do the same in reverse.  It is a bit of a mating dance.