Why was I invited to an interview if the position was then filled internally?

I was invited to an interview, which went very well. For example, I was assured that, given my skills, I would need less than the planned training period. Then, a week later, I received a call, and I was completely shocked. The reason for the rejection was "unfortunately, we have filled the position internally." So…