Some places the situation could be untenable for you, either because you just can't handle it, or because there are real outcomes that are pretty negative for you (such as the guy who posted recently that his boss refused to meet with him).
Other times maybe it is time to realize that not everything is easily measured metrics or technical skill and so forth.
I've worked with a lot of younger guys fresh out of school and their approach is very academic where they really enjoyed the feedback / praise / clear pecking order of things like grades. Very good grades always rewarded them and they were told exactly how to get them. Then they entered the world where things were far less clear. Some really struggled when they felt like they were passed over for someone they thought were of lesser skills than them.
Sometimes they were right that the other person wasn't very good at their job, other times they simply didn't appreciate the other aspects that went into that job that aren't easily measured and the fact that the other guy's code or work that wasn't as academically "better" really wasn't part of the equation... as much as they wanted someone who could talk to customers, or get along with coworkers, or something like that.
In short, it depends on your situation.
It give insights a) on why this happens and b) what scope for action you have (a lot).
ad b) i recommend two sided strategy> continue to do your best work while not caring about it. - and - start "beening open for new oportunities" side project job hunting & networking. it might cost some energy, but either the situation in your job improves and you can keep your job, and if not, you have a head start when your job hunting gets serious.
In a typical business environment there are usually multiple stakeholders who attack a given problem from different (often times opposing) angles. This doesn't automatically make one side more correct _or_ more competent than the other.
When you rise to power you can take better care to promote the right people. But according to what "right"? This is not a one dimensional problem.
Then we have the issue of 70% of the population thinking they are of above average competence.
...
That said, if it's a significant issue at your current work place I suggest you start looking for a new, better, place. And highlight the issue. People will get angry, and you might loose your job.