I spent a year shadowing a role at my company. I seconded there for a month, took over the role for no additional pay when staff were sick, took the necessary exam, studied for the second exam in my own time (beyond the requirement) and spent my free time revising my knowledge and reading up on industry trends.
When a vacancy came up I applied, had a thoroughly enjoyable interview, and scored 92% on the competency exam. Three other candidates interviewed, but they didn't have the relevant qualifications and openly admitted they'd messed up the test. They had, too, with low scores. Pension law and Mortgage guidelines aren't everyone's cup of tea.
They gave the job to Fred.
Fred? Who's Fred?
Fred didn't even apply. Fred was just sitting at his goddam desk. He'd applied for the LAST vacancy and hadn't gotten it, a year ago. Fred hadn't applied for THIS vacancy.
They said all the current candidates 'did well' and thanked us for our time.
Now the ones who'd failed the comp. test accepted it. They admittedly hadn't displayed the product knowledge but still felt aggrieved that the job had gone to some random bloke who hadn't even applied.
I was frankly fucking enraged. Call it what you like, but they offered me no decent feedback whatsoever as to why I'd 'failed', no tips, no nothing, and they - THEY! - had been the ones who'd been priming me for a year for the next vacancy! With the secondment opportunities and experience they'd been feeding me they were practically training me up for it. Why? Why go to all that hassle just to put on a big recruitment performance and hire a man who. didn't. even. apply.
I complained. They petted me on the head and ultimately made it clear they thought I was acting like a spoilt brat.
Fred quit within 6 months. Bit of a stressful role. They looked to me but I gave them the office equivalent of the finger and handed my notice in.
I'm not sure what you can do OP. Launching a legal challenge is expensive and uncertain, burning bridges along the way. Personally, I'd be flipping them the bird and making it clear that you went for that job because you're ambitious and you want more, and if they can't provide that they can swivel. Start looking for something else. They've lost you. Hopefully they'll be sorry they shoved you out, and are stuck with Dr Randomdude who's going to have to be shown the ropes.