It came to pass after these events, that God tested Avraham, and said to him "Avraham", and he said "Here I am". (Breishit 22:1)
According to my hopefully complete search, the phrase "after these events" (אחר הדברים האלה or a variant) appears twelve times in Tanach (Breishit 15:1, 22:1, 22:20, 39:7, 40:1, 48:1, Yehoshua 24:29, Melachim Alef 13:33, 17:17, 21:1, Esther 3:1, Ezra 7:1). In general, its usage is pretty clear. It introduces an event that is not an obvious or immediate consequence of the previous event, but the two events fit together as part of the overall story arc. For example, after Avraham defeated the four great kings via a surprise ambush, God appeared to him to promise protection (15:1). And after Yosef became the leading slave in Potifar's household, Potifar's wife developed an attraction for him and propositioned him (39:7).
As I see it, there is only one case which seems to violate this pattern, and that is the first verse of the Akedah passage. Exactly which events before the Akedah is the verse referring to - events which should be somewhat distant in time, and nevertheless thematically connected?
Let's look at several of the stories that precede the Akedah, numbered by chapter, and see if they can explain this role. Our criteria should be that the story is close to the Akedah ("these events" would seem to refer to the immediately preceding events), and that the the Akedah has a logical connection to it.
18-19: Angels visit Avraham; then proceed to Sedom, rescue Lot, and destroy the cities.
20: Avimelech takes and returns Sarah
21a: Hagar and Yishmael are expelled
21b: Avraham and Avimelech make a treaty
Chapter 21, story b
Rashbam discusses the phrase "after these events" here, taking the same basic approach that I do, and says that the event in question is 21b. Since Avraham had been promised the entire land of Israel, he should not have made a treaty that would effectively cede part of it to Avimelech's descendants. This was a sin, and the pain Avraham must have felt while preparing to sacrifice Yitzchak was the resulting punishment.
This is quite a good answer. It involves the immediately preceding event to the Akedah - a great advantage. It also explains well the delicate conditions in which the phrase "after these events" can be used - the events must be connected enough that they are linked, but not connected enough (temporally or naturally) that they are one story. But this answer is not perfect.
For one thing, it is not absolutely clear that the treaty was a sin. Avraham's inheritance was generations away (after a necessary exile). Who knew if Avimelech's descendants would still be around then, and even if they were, perhaps they could convert or otherwise integrate into the Jewish people.
For another thing, it's not at all clear that the Akedah was a punishment. Avraham's immediate suffering in the Akedah ended with a promise of great reward, a promise that presumably outweighed the suffering. If the Akedah as a whole was good for Avraham, how could it be a punishment? And why would he only receive the chance to merit the promise after sinning? Perhaps if the promise were simply a restoration of previous promises which had been nullified through Avraham's sin, but if so why does it go beyond them to swear (for the first time) that the promise would come true? And Avraham only suffered in the Akedah because he was willing to sacrifice his son - it seems awkward that if he rejected the command he wouldn't have suffered at all.
Also, if the Akedah were a punishment for 21b in particular, you might the Akedah to allude to 21b. But it contains no reference to the land, either in its command or in the eventual reward. The latter is striking especially because many other Patriarchal blessings do mention the land. This blessing promises Avraham numerous offspring (logical, since he showed his willingness to sacrifice his offspring), and adds that "all the nations of the earth shall be blessed through your offspring" - which if anything could be in the same spirit as the treaty with Avimelech.
These questions are not insoluble, but they do provide motivation to search for other possible answers.
If I remember correctly, some sources (I don't remember which) say the Akedah is a punishment for chapter 20. The events in Avraham's life can be divided into the clearly moral and God-fearing, and the questionably so. In the latter category, chapter 20 is perhaps the most questionable. Avraham described Sarah as his sister, leading Avimelech to take or abduct her, even though he already knew (from Egypt) that this description could lead to tragedy. Avraham says he did this because "I said there was no fear of God in this place" (20:11), but this possibility is contradicted when God appears to Avimelech and "the people feared greatly" (20:8). There could certainly be a sin here. Whether it is a greater sin than 21b, or more thematically related to the Akedah, is up for debate. But textually, chapter 20 is much further from the Akedah than 21b, which makes it less likely, all things being equal. And if you don't think the Akedah is a punishment, you'd have problems with this explanation too.
I think Chapters 18 and 19, and likely any earlier chapter, can be excluded right off the bat. Textually they are very far from the Akedah, and there is no clear thematic connection - not even any obvious sins by Avraham whose punishment might not be immediate.
Chapter 21, story a - Rashi
First of all: While this story does not immediately precede the Akedah, there is a rather good basis for connecting it anyway. This is because story 21b opens with "And it was, AT THAT TIME" - indicating that 21a and 21b are roughly simultaneous, despite their unrelated subjects. This is further strengthened by the general way Breishit tells of Avraham's life, in which the subjects of stories tend to alternate - quite elegantly in my opinion - for example the two Avimelech stories which are separated by 21a. Similarly, the Akedah comes two stories after 21a.
Now to Rashi's opinion. Rashi, based on Chazal, identifies 21a as the "events" to which the Akedah is linked. He suggests two possible narratives for how this occured:
1) At Yitzchak's weaning party, Avraham ate and drank, but is not recorded as having offered to sacrifices to God (as sometimes happens in other festive meals in Tanach, like Shemot 18:12). The "accuser" (Satan) noted this apparent lacking, to which God responded that Avraham would even sacrifice Yitzchak, subject of the party, if asked.
2) Yishmael boasted that he was circumcised at age 13 - more painful than Yitzchak's circumcision as a baby. To which Yitzchak responded he would even sacrifice his entire body, if asked.
In each case, God/Yitzchak then had the chance to prove their statement, through the Akedah.
This avoids the possible difficulties in saying the Akedah was a punishment. Of course, it opens up new questions as to what the purpose of the Akedah was - but the philosophical issues involved are too broad for this post. In any case, Rashi's approach works fine as midrash - inventing events that are not in the text in order to enbody broader philosophical considerations. But because those events are not in the text, it suffers on the level of pshat.
Chapter 21 - my ideas
I was recently thinking about what "after these events" could refer to, and I came up with two more ideas, one from 21a and one from 21b. Whether they are more or less convincing than the above suggestions, readers can judge for themselves.
In 21a, Sarah insists on expelling Hagar and Yishmael. Avraham is unhappy at this, but God tells him to do so, and he obeys.
The Akedah opens with the command to sacrifice "your son, your only son". This description is much more true after Yishmael has been banished from Avraham's life - one would expect never to return. The Akedah happens after Yitzchak has effectively become the only son. Drawing a connection to that event emphasizes the difficulty of the Akedah. Not only is it more emotionally difficult to lose your "only" son, but a major philosophical challenge of the Akedah is highlighted: how can the "only" son be killed before begetting the great multitude that God promised through him?
In 21b, we see a different angle.
The two Avraham/Avimelech stories have similarities - for example, in each Avimelech is morally blameless despite having taken Avraham's wife or well. But the difference are more striking. When Avraham first met Avimelech, he was an insecure nomad who roamed from place to place, each time lying about Sarah to preserve his own life. Now, Avraham lives in one place for many years (21:34), and is so successful enough that Avimelech says "God is with you in everything you do" (21:22). Then, Avraham was a guest of Avimelech; now Avimelech travels to ask favors from Avraham. Then, Avimelech received prophecy and demonstrated fear of God; now God is with Avraham. Avraham has spent much of his life wandering and worrying. From now on, we will see, he lives in stability and material comfort. And after 21a, he finally has a son through Sarah. In 21b, it appears as if Avraham's difficulties in life are over, and God's hashgacha pratit over him can be taken for granted.
Perhaps it is appropriate that the Akedah command comes at this moment. The incongruity of the command - morally and emotionally - is highlighted by the circumstances Avraham reaches in 21b, which otherwise seem to be "happily ever after". If Avraham were suffering then we could see the Akedah as yet one more inexplicable example of "hester panim". Only when everything else seems to make sense can we be shocked by the one command that cannot be understood.