Stuff like this really turns me off about the Olympics.
Well, to give a positive spin to it:
1. Sometimes players who are overlooked by their home countries for political reasons/favorisem get a 2nd chance (but I'll admit, that's not normally what it's all about...)
2. Some sports have super strict regulations about who can play for a country. Rugby for example, requires 3-5 years of no play period before you can switch representation, unless you're able to prove a solid connection to the country you want to switch to (your parents/grandparents were born there, you lived in the country non stop for at least 36 months).
(Judo is the complete opposite, and so you end up with a Judoka that represented 1 country in 2016, another in 2020(1) and will represent a 3rd(!) country in 2024!)