It appears that this is not settled case law, with the most recent case in the 9th district court (basically all of the west coast) ruling that at least public officials have the right to have affairs with coworkers:
https://www.sfchronicle.com/news/article/Police-can-t-be-fir...Other appeals courts have ruled otherwise, but the 9th district court has had a couple of precedents in the past, according to the article.
Personally, I think it's an interesting issue. If the company fires the higher ranked employee, they are probably losing more value.
It's also interesting that I think everyone would agree that it would be absurd to fire any employee if they were a married couple - yet absent the (mostly religious and tax related) binds of marriage, there's some moral judgment cast upon the participants. It seems so puritanical and absurd. What if the two employees got married before anyone found out about the affair? I bet they'd be protected both legally and in terms of moral or business implications.
It appears many states actually prevent firing based on marital status: https://www.wsj.com/articles/SB111041550490175318
From that one, "One reason is that about 20 states and many cities ban employment discrimination on the basis of marital status. If a married employee who has an affair is fired and an unmarried employee who has an affair isn't, the fired employee in those states conceivably could claim illegal discrimination, attorneys say. Thus, many employers turn a blind eye to marital cheating."