Question: Few days ago I appeared in a postdoc interview. The PI was very much impressed with my resume and the interview went very well. The PI asked me when do you want to join. The next day he asked recommendation letters from two of my references (I am sure that they will give me a very good recommendation). After 2 weeks I got the rejection letter. How to interpret this rejection (he told me that the position is filled by some other candidate). This will be useful for my future postdoc endeavors.

I politely asked him the reason. He did not reply. 

Thanks in advance. Sorry if this question is inappropriate.

Answer: 
There isn’t anything to interpret. The only conclusion you can draw is that there was another candidate whom the professor thought would be a better fit for the position, for an unspecified reason.

Our minds have a psychological tendency to want to fill in a lack of information with speculation and beliefs. The added information you have in this case is literally zero, so you must resist the urge to “interpret”; it is futile and serves no useful purpose.

Good luck with the job search!
It is impossible to say without more information, which you should seek. It may be that the PI in question didn't have final say, or some funding evaporated, or ...

It isn't out of the question that it was just a mistake. 

It may also just be that they found someone they liked better or thought would be a better fit in the interim. 

If you feel comfortable with the PI, you could just ask (nicely) what happened and that any feedback would be appreciated. It may not be possible for him to give you much information, but you might learn something. 

It would be good to know if there was a deal-breaker somewhere, but you may have no way to learn that. 

But in general, if you got a good feeling about the interview, it probably doesn't say anything about your future. Carry on, do your best. 

While it is true that some people will act very positively in person, just to avoid any potential conflict, don't let that realization get in the way of acting positively and naturally yourself in future interviews. You can't control the things you can't control. The PI may have acted toward other candidates precisely as he acted with you, but then had to make a choice.