As a general matter, yes, a company can do this: companies are free to decide how to recruit for positions (including whether to post internally, or allow existing staff to apply); who to hire or promote for them; whether to retain, or lay off or terminate staff, etc. The fact that you have consistently met expectations has no legal effect as a general matter--it may make what the company is doing a bad business decision, but the law does not require good decisions.The exceptions, or when they can't do this:1) You have a personal employment contract which is violated by this behavior;2) There is a union or collective bargaining agreement which is being violated;3) The company, in doing this, is discriminating against you because of your race, sex, religion, disability, or age over 40 (under federal law; state law may add a few more  protected categories, like sexual orientation or national origin).Other than the above, unfortunately, the company should be able to do this.