It’s not uncommon for illegitimate children to be brought up under the family since you never know when your legitimate heirs might die from the plague or wars, etc… Depending on the situation, they can also be used as political bargaining chips or shields for the burdens of your legitimate children.
For daughters they can be given to useful but unpleasant matches so the legitimate daughter doesn’t have to, while the family still reaps the benefits. In this case, the royal palace is a shitshow of malice, machinations, and manipulations which the Duke sis not want his “real” daughter to endure. By using Olivia, he can spare the daughter he actually cares about while maintaining the benefits of a royal connection. He may have been aware of the prince’s blatant infatuation with another woman even before the wedding (though it’s not uncommon for royalty, or any nobleman to cheat). Another issue is that any woman marrying into the royal family would have almost no power to divorce, separate, or leave no matter what mistreatment they have to endure unless their spouse allowed it. At least with another noble, his real daughter would be able to protest and/or leave if things got rough.
It was common for kings to draft soldiers by asking for a son from each noble family, so in this case, you can send your bastard son to war, to keep your legitimate child safe at home. On the flip side, if your legitimate heir dies at war, your bastard can be used as a secondary heir so that your distant family can’t take over your title when you die.

I just had to make another comment. Anyone knows why her father couldn’t just bribed her to stay tf out of her family? Did her mother threaten to expose something so that the duke will take her in? This could’ve been avoided if she were to be sent somewhere else other than his house..