Why does Mosaic Law insist on primogenitur even when the dad despises the first born son's mother? If a man has two wives, one of them loved and the other disliked, and if both the loved and the disliked have borne him sons, the firstborn being the son of the one who is disliked, then on the day when he wills his possessions to his sons, he is not permitted to treat the son of the loved as the firstborn in preference to the son of the disliked, who is the firstborn. He must acknowledge as firstborn the son of the one who is disliked, giving him a double portion of all that he has; since he is the first issue of his virility, the right of the firstborn is his.
  (Deuteronomy 21:15-17)


Why does the writer assume that like or dislike of the wife will map neatly to like or dislike of the son? In my experience and reading, this is not necessarily the case.

In case you're wondering, the line he is not permitted to treat the son of the loved as the firstborn in preference to the son of the disliked does, in fact, strongly imply that he is expected to wish to do this. Otherwise, the regulation prohibiting it would not be necessary.
This Mosaic Law on family inheritance is borne out of the story of Jacob and Joseph.

As you may remember, Jacob loved Rachel, and worked 7 years for her uncle, Laban, in order to be able to marry her.  Sadly, Jacob must have gotten really drunk, because of the day of his wedding, he finds out that Laban has tricked the trickster, and he's ended up being married to Rachel's older sister, Leah.  This being the day of polygamy, Laban says "Hey - don't worry! Just give me another 7 years, and you can have Rachel."  

As a dad whose first daughter is named Rachel, I can understand why Jacob would worked 14 years as a bargain. But I digress.

Once Jacob has the two wives, the baby-making war begins. God sees Leah's sorrow and devotion, and so opens her womb first.  Jacob's first-born son, Rueben, should, as the first born son, have all the privileges. But, the truth is that Jacob loves Rachel, not Leah. As the story continues, Leah keeps popping out the little ones, but Rachel can't seem to make a baby.  Much fuss ensues, and like any good modern reality series goes, Rachel gets Jacob to make babies with her maid, then Leah does the same thing, and before you know it, Jacob has a lot of boys - but Rachel is still not pregnant.

Then, finally, the big day arrives.  Rachel gets pregnant, and Jacob is way, way, happy.  The boy, Joseph, quickly becomes Jacobs absolute favorite.  Hands down. In fact, Jacob loves Joseph so much that he gives him a technicolor coat and arranges for Andrew Lloyd Webber to write about him nearly 4000 years later. Well, we all remember what happens from there - big brothers get angry, sell Joseph off into slavery, and pretty much fill out the rest of Genesis.  


  (Incidentally - bonus points if you know who Rachel's only other boy is.  That's right - Benjamin - the son of his right hand. Rachel dies in childbirth, and when Joseph later uses a ruse to put his only full brother in prison, the other boys realize this would pretty much kill their dad, hence the hysterics to get him back.)


This part of the covenant then, is as much symbolic as it is practical.  It is direct, received wisdom from the experience of Jacob and his favorite sons.  

Is it possible for a despised wife to have a beloved son? Sure.  But we don't have any biblical stories about those prior to this law. The more practical point is "Don't gip your boys in the will," but the precedent that backs it up has its roots in history.