user8509: Quoting FIDE rulebook:

This capture is only legal on the move following this advance and is called an ‘en passant’ capture.

Quoting Wikipedia:

The en passant capture must be made at the very next turn or the right to do so is lost.

Why?

I know the basic story of en passant and I'll just paraphrase it here: A rule was added to let pawns move two squares forward on its first move. Someone said something like, what if a pawn uses this to escape from an enemy adjacent pawn? Then the basic pawn skeleton/framework would be changed! So we must have an en passant to preserve the same chess framework.
Okay that part makes sense, but why does it have to be on the very next move? Was that part of the rule only added later? Why was it added at all? When two pawns are diagonally adjacent confronting each other, they don't have to capture immediately or else forefeit the ability to capture. So the concept of the "ghost pawn", if you don't capture it immediately, and the other player doesn't move it, seems to me like it should still be there and available for capture as long as it's there.
Does anyone know why this part of en passant was created?

Optional Background: In case you're curious, I come from a programming background. Of all the special moves, en passant is (was, see below) the hardest to program. Not only is it the only move where the capturing piece moves to a blank square, but it's the only move that "disappears" if you don't take it. That means it's a move where the total board position is not enough information to generate all moves. (That's true for castling too, which already has its fair share of tricky rules.) Two enemy pawns could be adjacent on the 4th or 5th rank, surrounded by blank squares, but you still don't know if en passant is possible. You have to check the previous move.
Or so I thought. Now that I'm revisiting this, I figured out a clever way to implement en passant without checking the move log. Don't generate it at turn start. Generate it at move_take, specifically at the end of a 2-step pawn move. But store it in a special move array since the normal one gets cleared at every inc_turn. Then migrate and clear appropriately at gen_all_moves. That way, if ep is not taken, it doesn't generate itself on the next move because you didn't move that same pawn two steps on the next move. Just remember to check both sides of the pawn and create two ep moves if two enemy pawns are there.
Castling was implemented with the help of a "moved" boolean in every piece, which is also useful for a pawn's first move of course. Even if the King and Rook are in the right spot, you use that to see if the King/Rook has moved before. No need to check the move log. But I will say that Castling is now the hardest move to implement because you gotta check if the path is under attack. En passant is no longer the hardest now that I thought of the clever way.

user15221: Your programming description relies on variable name specific to your program, so it's hard to understand what you're saying, but one way to program this is to to have a "double pawn move" boolean. To makes things simpler, let's assume that white is the one making a double pawn move. To move a pawn two space, white first moves the pawn one space, and set that pawn's "double move" boolean to true. If any of the opponent's pawns have a true "double pawn move" booleans, then they have only two options: take or pass. So now black has only two legal move (three if two pawns are adjacent). Black can either capture the pawn, or pass. If black passes, then it's now white's turn. But if a player starts their turn with a "double pawn move" boolean being true for any of their own pawns, they aren't allowed to make any move other than advancing that pawn, and then the boolean is set to false. If black captures the pawn, then the boolean is set to false, and it's now white's turn. 
In other words, you can think of en passant not being that white makes one move consisting of the pawn moving two spaces, and then black has the en passant option only on the next move, but rather that white makes a move consisting of the pawn moving one space, black makes a move consisting of either capturing that pawn or passing, and then, if the pawn is still on the board, white makes a move of advancing the pawn again. The en passant option exists only for the intermediate move (the one in which black either captures or passes) because that's the only move where the pawn is in the right location to be captured.
However, there is a corner case presented here: https://www.futilitycloset.com/2010/06/09/intercepted/ . As en passant is currently implemented, it's legal to make a double move if you kings is not in check after the second advancement, even if you king is in check after the pawn is advanced only one space. So your code would have to take that into account.

user33047: Regarding the en passant rule requiring the capture being made immediately or not
at all is due to a situation where if an opposing piece on the next move moved onto the vacant square where the en passant would occur, then TWO captures could be made
at ONCE with one being done by en passant and the other being a normal pawn capture.

user11629: Interesting question, though I am not sure there is a good answer which could be backed by sources. I can think of the following motivations:

If you imagine your pawns to be real "armies", then if one army is passing you at high speed (double step), you need to act immediately (if you wish to do so) and cannot wait before the other army is far away.
Practicality. Keeping track of all possible en passant captures could become tricky. What if one or both of the pawns involved get replaced by another pawn of the same color...
In chess, if a piece attacks a piece of the same type, the other piece at the same time attacks the first piece. With indefinite en passant you would create an asymmetry where one pawn could capture another pawn but not vice versa.
Indefinite en passant would be too big a change to the game as it was known before the introduction of en passant.
(see Ken Wei's answer): With a black pawn on a4 and a white pawn on b2. You need to compare the option of playing b2-b3-b4 in two moves (which would lose you a tempo) with the double step (which would put you in danger of indefinite capture). 


user4418: The reason is very simple. If white has a pawn on d5 preventing a black pawn on e7 from moving then the move e7-e5 circumvents that. To keep things fair when the double pawn first move was introduced then the en passant rule was also introduced so that white wouldn't lose the possibility to capture. However going back to the pre-double move era if black plays e7-e6 and white doesn't capture immediately then black can play e6-e5 on the next move and white has lost his chance forever. That is reflected in the restriction of en passant to the move immediately following the double pawn move.

user7473: A pawn which 'exposes' itself to en passant will be distinct from one that doesn't. Say, for a black pawn on a4 and a white pawn on b4: giving black the option of playing ...axb3 at any time after b2-b4 means that the moves b2-b4 and b3-b4, which seemingly lead to the same position, have long-term implications as it depends too much on the past. In particular, when the pawn stands on b2, white would need to weigh the pros and cons of moving his pawn to b4 in one or two moves (where the con is giving black a long-lasting right to take on b3).
Or, in the spirit of the motivation of en passant that you correctly described, permanently stopping a two-square pawn from 'escaping' would greatly neglect (or complicate) the benefit of being able to move two squares forward.
Another practical reason because it's just much simpler for humans: with more than one pawn on the board, it would be complicated to keep track of en passant rights on all of them. (Someone once suggested that pieces be able to capture en passant at some FIDE meeting; needless to say, it was laughed out of the room --- that said, I can't recall the source of this story.)
One may ask a similar (opposite?) question about castling rights; the 'simpler' option may arguably be to always allow castling as long as the pieces are back on their original squares, but that too has strong implications, one of which is a reduced importance of development.
Generally, the special moves in chess have restrictions associated with them to ensure that they don't change the way the game 'looks' after the time these special moves are made (playing ...axb3 to take a white pawn on b4 looks completely unlike the old game, so it's only allowed for one move). After all, the rules were designed by humans, arguably arbitrarily.

user1485: The OP asked me to provide sources supporting the claim that the double step was originally a double move. I'll do my best.
The immediate predecessor of modern chess, the game Shatranj, did have pawns (sarbaz), but no double step. The pieces in Shartanj had relatively weak powers, and gameplay, especially in the opening, was generally slow.
In medieval times they addressed this problem by starting the game from certain tabiyas, battle arrays where the opposing forces were already in contact.
A more recent western invention to speed up the play was to allow double-initial moves of pawns.
From A Short History of Chess by Henry A. Davidson, Chapter 7:

The Initial Double Move. Not until about 1550 did the pawn uniformly enjoy the power of moving two squares for his first move. The reason for the final adoption of the rule was simply that openings became conventionalized. White moved P to K3 [e3]; Black did likewise. Then each pushed the pawn up a square. Since this was the usual opening, the modern practice of allowing both moves at once, thus speeding up the game, was introduced. As a matter of fact, this pawn privilege was the last, not the first, of a series of special consecutive-move privileges.

Davidson then very briefly discusses consecutive-move rules in earlier versions of chess.
There was also at some point an option to move two different pawns simultaneously one step each. Quote from the same book:

During the seventeenth century a convention was in effect permitting a player to open a game by moving both rooks' pawns simultaneously one square each.
  [...]
  Perhaps the idea was that moving two pawns each one square was the equivalent of moving one pawn two squares.

I think this historical context provides some rationale for why the en passant rule was introduced. If the double step is actually a double move, then it's quite logical that the opponent should be given a chance (on the next move) to capture the pawn after the first step. (See also Brian Towers' answer.)

8509: <p>Quoting <a href="http://www.fide.com/fide/handbook?id=124&amp;view=article" rel="nofollow noreferrer">FIDE rulebook</a>:</p>

<blockquote>
  <p>This capture is <strong>only legal on the move following this advance</strong> and is called an ‘en passant’ capture.</p>
</blockquote>

<p>Quoting <a href="https://en.wikipedia.org/wiki/En_passant" rel="nofollow noreferrer">Wikipedia</a>:</p>

<blockquote>
  <p>The <em>en passant</em> capture must be made <strong>at the very next turn</strong> or the right to do so is lost.</p>
</blockquote>

<p><strong>Why?</strong></p>

<hr>

<p>I know the basic story of <em>en passant</em> and I'll just paraphrase it here: A rule was added to let pawns move two squares forward on its first move. Someone said something like, what if a pawn uses this to escape from an enemy adjacent pawn? Then the basic pawn skeleton/framework would be changed! So we must have an <em>en passant</em> to preserve the same chess framework.</p>

<p>Okay that part makes sense, but why does it have to be <strong>on the very next move?</strong> Was that part of the rule only added later? Why was it added at all? When two pawns are diagonally adjacent confronting each other, they don't have to capture immediately or else forefeit the ability to capture. So the concept of the "ghost pawn", if you don't capture it immediately, and the other player doesn't move it, seems to me like it should still be there and available for capture as long as it's there.</p>

<p><strong>Does anyone know why this part of <em>en passant</em> was created?</strong></p>

<hr>

<p><strong>Optional Background:</strong> In case you're curious, I come from a programming background. Of all the special moves, <em>en passant</em> is (was, see below) the hardest to program. Not only is it the only move where the capturing piece moves to a blank square, but it's the only move that "disappears" if you don't take it. That means it's a move where <strong>the total board position is not enough information</strong> to generate all moves. (That's true for castling too, which already has its fair share of tricky rules.) Two enemy pawns could be adjacent on the 4th or 5th rank, surrounded by blank squares, but you still don't know if <em>en passant</em> is possible. You have to check the previous move.</p>

<p>Or so I thought. Now that I'm revisiting this, I figured out a clever way to implement <em>en passant</em> without checking the move log. Don't generate it at turn start. Generate it at move_take, specifically at the end of a 2-step pawn move. But store it in a special move array since the normal one gets cleared at every inc_turn. Then migrate and clear appropriately at gen_all_moves. That way, if ep is not taken, it doesn't generate itself on the next move because you didn't move that same pawn two steps on the next move. Just remember to check both sides of the pawn and create <strong>two</strong> ep moves if two enemy pawns are there.</p>

<p>Castling was implemented with the help of a "moved" boolean in every piece, which is also useful for a pawn's first move of course. Even if the King and Rook are in the right spot, you use that to see if the King/Rook has moved before. No need to check the move log. But I will say that Castling is now the hardest move to implement because you gotta check if the path is under attack. En passant is no longer the hardest now that I thought of the clever way.</p>
 15221: <p>Your programming description relies on variable name specific to your program, so it's hard to understand what you're saying, but one way to program this is to to have a "double pawn move" boolean. To makes things simpler, let's assume that white is the one making a double pawn move. To move a pawn two space, white first moves the pawn <em>one</em> space, and set that pawn's "double move" boolean to true. If any of the opponent's pawns have a true "double pawn move" booleans, then they have only two options: take or pass. So now black has only two legal move (three if two pawns are adjacent). Black can either capture the pawn, or pass. If black passes, then it's now white's turn. But if a player starts their turn with a "double pawn move" boolean being true for any of their own pawns, they aren't allowed to make any move other than advancing that pawn, and then the boolean is set to false. If black captures the pawn, then the boolean is set to false, and it's now white's turn. </p>

<p>In other words, you can think of <em>en passant</em> not being that white makes one move consisting of the pawn moving two spaces, and then black has the <em>en passant</em> option only on the next move, but rather that white makes a move consisting of the pawn moving one space, black makes a move consisting of either capturing that pawn or passing, and then, if the pawn is still on the board, white makes a move of advancing the pawn again. The <em>en passant</em> option exists only for the intermediate move (the one in which black either captures or passes) because that's the only move where the pawn is in the right location to be captured.</p>

<p>However, there is a corner case presented here: <a href="https://www.futilitycloset.com/2010/06/09/intercepted/" rel="nofollow noreferrer">https://www.futilitycloset.com/2010/06/09/intercepted/</a> . As <em>en passant</em> is currently implemented, it's legal to make a double move if you kings is not in check after the second advancement, even if you king is in check after the pawn is advanced only one space. So your code would have to take that into account.</p>
 33047: <p>Regarding the en passant rule requiring the capture being made immediately or not
at all is due to a situation where if an opposing piece on the next move moved onto the vacant square where the en passant would occur, then TWO captures could be made
at ONCE with one being done by en passant and the other being a normal pawn capture.</p>
 11629: <p>Interesting question, though I am not sure there is a good answer which could be backed by sources. I can think of the following motivations:</p>

<ol>
<li>If you imagine your pawns to be real "armies", then if one army is passing you at high speed (double step), you need to act immediately (if you wish to do so) and cannot wait before the other army is far away.</li>
<li>Practicality. Keeping track of all possible en passant captures could become tricky. What if one or both of the pawns involved get replaced by another pawn of the same color...</li>
<li>In chess, if a piece attacks a piece of the same type, the other piece at the same time attacks the first piece. With indefinite en passant you would create an asymmetry where one pawn could capture another pawn but not vice versa.</li>
<li>Indefinite en passant would be too big a change to the game as it was known before the introduction of en passant.</li>
<li>(see Ken Wei's answer): With a black pawn on a4 and a white pawn on b2. You need to compare the option of playing b2-b3-b4 in two moves (which would lose you a tempo) with the double step (which would put you in danger of indefinite capture). </li>
</ol>
 4418: <p>The reason is very simple. If white has a pawn on d5 preventing a black pawn on e7 from moving then the move e7-e5 circumvents that. To keep things fair when the double pawn first move was introduced then the en passant rule was also introduced so that white wouldn't lose the possibility to capture. However going back to the pre-double move era if black plays e7-e6 and white doesn't capture immediately then black can play e6-e5 on the next move and white has lost his chance forever. That is reflected in the restriction of en passant to the move immediately following the double pawn move.</p>
 7473: <p>A pawn which 'exposes' itself to en passant will be distinct from one that doesn't. Say, for a black pawn on a4 and a white pawn on b4: giving black the option of playing ...axb3 at any time after b2-b4 means that the moves b2-b4 and b3-b4, which seemingly lead to the same position, have long-term implications as it depends too much on the past. In particular, when the pawn stands on b2, white would need to weigh the pros and cons of moving his pawn to b4 in one or two moves (where the con is giving black a long-lasting right to take on b3).</p>

<p>Or, in the spirit of the motivation of en passant that you correctly described, permanently stopping a two-square pawn from 'escaping' would greatly neglect (or complicate) the benefit of being able to move two squares forward.</p>

<p>Another practical reason because it's just much simpler for humans: with more than one pawn on the board, it would be complicated to keep track of en passant rights on all of them. (Someone once suggested that pieces be able to capture en passant at some FIDE meeting; needless to say, it was laughed out of the room --- that said, I can't recall the source of this story.)</p>

<p>One may ask a similar (opposite?) question about castling rights; the 'simpler' option may arguably be to always allow castling as long as the pieces are back on their original squares, but that too has strong implications, one of which is a reduced importance of development.</p>

<p>Generally, the special moves in chess have restrictions associated with them to ensure that they don't change the way the game 'looks' after the time these special moves are made (playing ...axb3 to take a white pawn on b4 looks completely unlike the old game, so it's only allowed for one move). After all, the rules were designed by humans, arguably arbitrarily.</p>
 1485: <p>The OP asked me to provide sources supporting the claim that the double step was originally a <em>double move</em>. I'll do my best.</p>

<p>The immediate predecessor of modern chess, the game <a href="https://en.wikipedia.org/wiki/Shatranj" rel="noreferrer">Shatranj</a>, did have pawns (<em>sarbaz</em>), but no double step. The pieces in Shartanj had relatively weak powers, and gameplay, especially in the opening, was generally slow.</p>

<p>In medieval times they addressed this problem by starting the game from certain <a href="https://en.wikipedia.org/wiki/Shatranj#Openings" rel="noreferrer">tabiyas</a>, battle arrays where the opposing forces were already in contact.</p>

<p>A more recent western invention to speed up the play was to allow double-initial moves of pawns.
From <a href="https://books.google.no/books?isbn=0307828298" rel="noreferrer">A Short History of Chess</a> by Henry A. Davidson, Chapter 7:</p>

<blockquote>
  <p><em>The Initial Double Move</em>. Not until about 1550 did the pawn uniformly enjoy the power of moving two squares for his first move. The reason for the final adoption of the rule was simply that openings became conventionalized. White moved P to K3 [<code>e3</code>]; Black did likewise. Then each pushed the pawn up a square. Since this was the usual opening, the modern practice of allowing both moves at once, thus speeding up the game, was introduced. As a matter of fact, this pawn privilege was the last, not the first, of a series of special consecutive-move privileges.</p>
</blockquote>

<p>Davidson then very briefly discusses consecutive-move rules in earlier versions of chess.</p>

<p>There was also at some point an option to move two different pawns simultaneously one step each. Quote from the same book:</p>

<blockquote>
  <p>During the seventeenth century a convention was in effect permitting a player to open a game by moving both rooks' pawns simultaneously one square each.
  [...]
  Perhaps the idea was that moving two pawns each one square was the equivalent of moving one pawn two squares.</p>
</blockquote>

<p>I think this historical context provides some rationale for why the en passant rule was introduced. If the double step is actually a double move, then it's quite logical that the opponent should be given a chance (on the next move) to capture the pawn after the first step. (See also Brian Towers' answer.)</p>
