Seems like illegitimate child is bothersome only when they come from commoners. You are right, it doesn't make sense, but the story gives you arguments to justify parts of the story and then forgets about them once they have been used.
The statement of "illegitimate" is there, and it helps to add drama, but you don't give it much thought after the plot goes over it.
So... Hugs my friend, you made a good point

There's this thing bothering me with the logic. They look down on illegitimate children and would never marry them and so on, okay that is logical. But, in the case they do marry an illegitimate child, they don't want a child with that person? Like, it's so bad that the children you have with your legal spouse, who is an illegitimate child, are not suited to be heirs and there will be problems with succession. So, the solution to that problem is to have a child with someone whom is not your legal spouse, and have that child be the heir. BUT!!! That child would also be illegitimate!!!!! Like wtf, make it make sense!!! You look down on illegitimate children and won't have legitimate children with them, so your solution is to make more illegitimate children?????? It just seems so wild and completely stupid.