While Joseph's answer has much to commend it, I feel it is headed in the wrong direction. I don't think there is a need to suppose two sets of Abiathars and Ahimelechs where one is father-son and the other vice versa. First, 1 Kings 2:26-27 is clear that it was indeed the so-called "good" Abiathar it's talking about since verse 27 notes that his life was spared due to enduring the same hardships as David. Secondly, if the Ahimelech son of Abiathar and other Abiathar were so obscure so as to be mentioned once each in all of 2 Samuel and 1 Kings (8:17 and 4:4 respectively; Ahimelech a further 4 times in 1 Chronicles but that's not as early or detailed and will be discussed), how is it that this unknown Ahimelech got to be alongside Zadok if he wasn't prominent enough to even be mentioned?
It is clear that some time after the composition of 1 Chronicles, a scribe made the error of trying to "correct" what he thought was in 2 Samuel 8:17 and either he or someone else thought 1 Chron. 18:16, based on that verse, made a mistake in copying.
But why do I say copyist error and not error in the originals? First, for 2 Samuel to make such an error when the entire time he talks about Abiathar and no Ahimelech is illogical. Nor did someone come and try to replace Abiathar with Ahimelech for whatever purpose since he would have done it in more places at once (if it be supposed he did change other places, the scribes changing it back, they would have hardly not done this for 8:17 as well and I don't think they would have missed it as there would have been a lot looking for such a big error to go unnoticed). It couldn't have been an error on the part of the author of 1 Chron. as he acknowledges Abiathar as priest alongside Zadok in 1 Chron. 15:11. If it's supposed he came upon 2 Sam. 8:17 and changed his mind from Abiathar -> Ahimelech, would he not have changed he Abiathar reference just 3 chapter earlier to Ahimelech? So what happened in my opinion is this:
- Original of 2 Sam. 8:17 had Ab son of Ahi
- Original of 1 Chron. 18:16 and the other 4 references also had the correct name.
- Some time shortly after 1-2 Chron. was written, before the Septuagint in the 3rd century BC made the OT more widespread, a scribe saw 2 Sam. 8:17: "Zadok son of Ahitub, and Abiathar son of Ahimelech." Since Ahimelech was also a son of Ahitub, he got confused with the genealogy and thought he saw "Ahitub->Abiathar->Ahimelech" since that would've been the positioning of those three names and thought it was implying Abiathar was Ahitub's son and Ahimelech's father (how ironic), changing the names without reading the context fully (he saw son of and assumed it was a genealogy saying Abiathar and his son Ahimelech). A different scribe soon after compares 1 Chron. with 2 Sam, sees the discrepancy, changes 4 Abiathars into Ahimelechs but misses the Abiathar in 15:11 since he precedes 18:16 which first caught his eye as contradicting 2 Sam 8:17 and proceeded to correct the rest of the Abiathars (or perhaps another scribe though unlikely) all of which are found in 1 Chron. 24.
As for 1 Kings 4:4, our only evidence for a second Abiathar: most likely a copyist error that knew the pair names Zadok and Abiathar as the author wouldn't forget just 2 haters earlier that Abiathar was banished. If it were a competing tradition that didn't believe Abiathar was banished or hated it they probably would have added him everywhere else an not just there.
This is at least, my theory
"Thank you for your observations. My comments followed what I saw in the text, especially since the two Abiathars and Ahimelechs had respectively come from two different Levitical family lines. While the idea of copyist error is the most convenient explanation, it would however not be the most literal."
This is what I understand your position to be:
-"good" Ahimelech is the father of "good" Abiathar. "good" Ahimelech is referred to in 1 Samuel 21-22, and his son is "good" Abiathar in 1 Samuel 22-23 (called son of Ahimelech in 1 Sam. 23:6; 30:7) at least, and 1 Ki 4:4.
-"bad" Abiathar is the father of "bad" Ahimelech. "bad" Abiathar is mentioned in 1 Kings (except for 1 Ki 4:4) and maybe 1-2 Samuel//1 Chron 15:11? "bad" Ahimelech is 2 Sam 8:17 + 1 Chron. 24.
The Problem:
The Ahitub you refer to as the father of the "good" Abiathar/Ahimelech in 1 Chron. 6:7 (verse 11 refers to a different Ahitub), is the father of Zadok, and 1 Chronicles 6:7ff. makes no mention of any Abiathars or Ahimelechs as descendants of this Ahitub (father of Zadok). He might have had other kids ("good" Ahimelech one of them), but the text makes no mention of this.
The Abiathar of 1 Samuel 22 and on must be the "good" Abiathar according to you, however this Abiathar is the priest that serves David and shares in his troubles and you identify him as the "bad" Abiathar (1 Kings 2:26 also says the "bad" Abiathar shared in David's troubles; no mention of the "good" anywhere but 1 Kings 4:4). There is no room for the "bad" Abiathar to suddenly displace this "good" Abiathar anywhere: 1 Samuel 22:20-23 clearly identifies the "good" Ahimelech as his father. 1 Samuel 23 and on clearly continue the story and call him the son of Ahimelech (even if we suppose the "bad" Abiathar also had a father named Ahimelech!).
Also, (bad) Abiathar wasn't relieved of being a high priest until Solomon's day so why does 1 Chronicles 15:11 say he and Zadok were priests, but then in 2 Samuel 8:17, 1 Chr 18:16; +ch.24 it's Ahimelech, of whom there is no mention after 1 Samuel 22, besides the singular name in 2 Samuel 8:17, whereas the rest of 1 Samuel, 2 Samuel, and 1 Kings speak of "Zadok and Abiathar the priests" and no Ahimelech? Moreover, 1 Kings 2:35 says that Zadok replaced Abiathar as priest - that is, there was only one high priest from now on.
Moreover, it doesn't stand to reason that either the "good" or "bad" Abiathars/Ahimelechs were from Eleazer's line because Zadok was from Eleazer's line and the other high priest was to be from Ithamar's (1 Chron. 24:3ff.). Since David created this division, the Ahimelech killed by Saul could've theoretically been of Eleazer, but the "good" Abiathar of 1 Ki 4:4 can't, unless Solomon abrogated this, but we know from 1 Kings 2:35 that the only change he made was to make Zadok sole high priest.
The only way I can see your solution working is if the Ahimelech of 1 Samuel 21-22 is the father of "bad" Abiathar (1 Sam. 22:20 till 1 Ki 2:26; 1 Chr. 15:11) who was the father of "bad" Ahimelech (2 Samuel 8:17; 1 Chr. 18:16; 24). Perhaps "bad" Ahimelech served alongside his father (and not Jonathan who is the only son to be given a story). And the "good" Abiathar of 1 Kings 4:4 shows up (unconnected to any "good" Ahimelech) to take the place of "bad" Abiathar (+Ahimelech? Perhaps unmentioned because unimportant or shared his father's fate). But besides this improbable convolution, what defeats this only solution that I can see is the fact that Solomon abrogated the dual priesthood after kicking out "bad" Abiathar (1 Ki 2:35).
A copyist error here isn't merely a convenient explanation here, it's a necessary one! And I don't see that the explanation with two Ahimelechs/Abiathars is more literal because of these very impossibilities in reconciling the texts.