As I understand it, ancient Jewish law was about inheritance not morality.
If a man died and had no son, his brother was expected to "Lie with" her and produce a son. That son was then declared the son of the dead man. It was all about inheritance. Women were not allowed to own property.